Skip to content

Commit f2648de

Browse files
committed
use a different method to conditionally register the pytest_xdist_auto_num_workers hook because the pytest_configure hook didn't work for some reason
1 parent 6277810 commit f2648de

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

python_files/vscode_pytest/__init__.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -914,15 +914,12 @@ def send_post_request(
914914
)
915915

916916

917-
def pytest_configure(config: pytest.Config):
918-
if config.pluginmanager.hasplugin("xdist"):
919-
920-
class XdistHook:
921-
@pytest.hookimpl(hookwrapper=True)
922-
def pytest_xdist_auto_num_workers(
923-
self, config: pytest.Config
924-
) -> Generator[None, Result[int], int]:
925-
"""determine how many workers to use based on how many tests were selected in the test explorer"""
926-
return min((yield).get_result(), len(config.option.file_or_dir))
927-
928-
config.pluginmanager.register(XdistHook())
917+
try:
918+
import xdist # pyright: ignore[reportMissingImports]
919+
except ModuleNotFoundError:
920+
pass
921+
else:
922+
@pytest.hookimpl(wrapper=True)
923+
def pytest_xdist_auto_num_workers(config: pytest.Config) -> Generator[None, int, int]:
924+
"""determine how many workers to use based on how many tests were selected in the test explorer"""
925+
return min((yield), len(config.option.file_or_dir))

0 commit comments

Comments
 (0)