def test_build_tree(snapshot): tree = result_tree.build_from_items(ITEMS, "/root") assert isinstance(tree, result_tree.BranchNode) assert tree.status == result_tree.TestState.INIT assert tree.short_id == "root" assert str(tree.nodeid) == "" serializer = result_tree.BranchNodeSchema() serialized_tree = serializer.dump(tree) snapshot.assert_match(serialized_tree)
def build_app( directory: str, watch_filesystem: bool, ) -> Tuple[flask.Flask, flask_socketio.SocketIO, runner.PyTestRunner]: """Build a Flask app to serve the API and static files.""" build_dir = pkg_resources.resource_filename(__name__, "web_client/build") LOGGER.debug("build_dir: %s", build_dir) static_dir = os.path.join(build_dir, "static") index_file = os.path.join(build_dir, "index.html") app = flask.Flask(__name__, root_path=build_dir, static_folder=static_dir) branch_schema = result_tree.BranchNodeSchema() socketio = flask_socketio.SocketIO(app) test_runner = runner.PyTestRunner(directory, socketio, watch_filesystem) @app.route("/") def index(): return flask.send_file(index_file) @app.route("/<path:path>") def send_build(path): LOGGER.debug("Sending file: %s", path) return flask.send_from_directory(build_dir, path) @app.route("/api/v1/result-tree") def tree() -> Dict[str, Any]: try: return branch_schema.dump(test_runner.result_tree) except Exception: traceback.print_exc() raise @socketio.on("run test") def run_test(nodeid): LOGGER.info("Running test: %s", nodeid) test_runner.run_tests(nodeid) @socketio.on("start env") def start_env(nodeid): LOGGER.info("starting env: %s", nodeid) test_runner.start_env(nodeid) @socketio.on("stop env") def stop_env(nodeid): LOGGER.info("stopping env: %s", nodeid) test_runner.stop_env(nodeid) @socketio.on("connect") def connect(): LOGGER.debug("Client connected") @socketio.on("disconnect") def disconnect(): LOGGER.debug("Client disconnected") return app, socketio, test_runner
def __init__( self, directory: str, socketio: flask_socketio.SocketIO, watch_filesystem: bool ): self._directory = directory self.result_tree = _init_result_tree(directory) self._socketio = socketio self._branch_schema = result_tree.BranchNodeSchema() self._leaf_schema = result_tree.LeafNodeSchema() self._node_index = result_tree.Indexer(self.result_tree) self._watch_filesystem = watch_filesystem self._watchdog_proc: Optional[multiprocessing.Process] = None
def __init__( self, directory: str, socketio: flask_socketio.SocketIO, watch_mode: str, ): self._directory = os.path.abspath(directory) self.result_tree = _init_result_tree(self._directory, watch_mode) self._socketio = socketio self._branch_schema = result_tree.BranchNodeSchema() self._leaf_schema = result_tree.LeafNodeSchema() self._node_index = result_tree.Indexer(self.result_tree) self._watch_mode = watch_mode self._watchdog_proc: Optional[multiprocessing.Process] = None if watch_mode == "autorun": self._run_test(nodeid.EMPTY_NODEID)
def test_parameterized_tests_removed(snapshot): items = [ SessionItem(nodeid) for nodeid in [ "path/to/test_params.py::test_params[alpha]", "path/to/test_params.py::test_params[beta]", "path/to/test_params.py::test_params[gamma]", ] ] items_missing_one_parameter = items[:2] tree = result_tree.build_from_items(items, "/root") tree_missing_one_parameter = result_tree.build_from_items( items_missing_one_parameter, "/root") assert len(items) == 3 assert len(items_missing_one_parameter) == 2 serializer = result_tree.BranchNodeSchema() serialized_tree = serializer.dump(tree) tree.merge( tree_missing_one_parameter, nodeid.Nodeid.from_string("path/to/test_params.py"), ) serialized_tree_after_merge = serializer.dump(tree) snapshot.assert_match(serialized_tree, "before_merge") snapshot.assert_match(serialized_tree_after_merge, "after_merge")