Skip to content

Commit 2f1a5a5

Browse files
committed
fix crash when xdist plugin is not enabled
1 parent 0928155 commit 2f1a5a5

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

python_files/vscode_pytest/__init__.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,13 @@ def send_post_request(
884884
)
885885

886886

887-
@pytest.hookimpl(hookwrapper=True)
888-
def pytest_xdist_auto_num_workers(config: pytest.Config) -> Generator[None, Result[int], int]:
889-
"""determine how many workers to use based on how many tests were selected in the test explorer"""
890-
return min((yield).get_result(), len(config.option.file_or_dir))
887+
def pytest_configure(config: pytest.Config):
888+
if config.pluginmanager.hasplugin("xdist"):
889+
class XdistHook:
890+
@pytest.hookimpl(hookwrapper=True)
891+
def pytest_xdist_auto_num_workers(
892+
self, config: pytest.Config
893+
) -> Generator[None, Result[int], int]:
894+
"""determine how many workers to use based on how many tests were selected in the test explorer"""
895+
return min((yield).get_result(), len(config.option.file_or_dir))
896+
config.pluginmanager.register(XdistHook())

0 commit comments

Comments
 (0)