From de77f6429cec833dda6398380ff5a32d26f5e046 Mon Sep 17 00:00:00 2001 From: DetachHead <57028336+DetachHead@users.noreply.github.com> Date: Thu, 20 Jun 2024 11:30:32 +1000 Subject: [PATCH] fix crash when running with xdist plugin disabled --- python_files/vscode_pytest/__init__.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/python_files/vscode_pytest/__init__.py b/python_files/vscode_pytest/__init__.py index b1dbf79a4b4c..d0148fa33754 100644 --- a/python_files/vscode_pytest/__init__.py +++ b/python_files/vscode_pytest/__init__.py @@ -902,3 +902,14 @@ def send_post_request( def pytest_xdist_auto_num_workers(config: pytest.Config) -> Generator[None, int, int]: """determine how many workers to use based on how many tests were selected in the test explorer""" return min((yield), len(config.option.file_or_dir)) + +class DeferPlugin: + @pytest.hookimpl(wrapper=True) + def pytest_xdist_auto_num_workers(self, config: pytest.Config): + """determine how many workers to use based on how many tests were selected in the test explorer""" + return min((yield), len(config.option.file_or_dir)) + +def pytest_plugin_registered(plugin, manager): + if manager.hasplugin("xdist") and not isinstance(plugin, DeferPlugin): + manager.register(DeferPlugin()) +