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()) +