Skip to content

Commit f05dc0f

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 f05dc0f

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

python_files/vscode_pytest/__init__.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@
99
import traceback
1010

1111

12-
from pluggy import Result
1312
import pytest
1413

1514
script_dir = pathlib.Path(__file__).parent.parent
1615
sys.path.append(os.fspath(script_dir))
1716
sys.path.append(os.fspath(script_dir / "lib" / "python"))
1817
from testing_tools import socket_manager # noqa: E402
19-
from typing import (
18+
from typing import ( # noqa: E402
2019
Any,
2120
Dict,
2221
List,
@@ -25,7 +24,7 @@
2524
TypedDict,
2625
Literal,
2726
Generator,
28-
) # noqa: E402
27+
)
2928

3029

3130
class TestData(TypedDict):
@@ -914,15 +913,12 @@ def send_post_request(
914913
)
915914

916915

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())
916+
try:
917+
import xdist # pyright: ignore[reportMissingImports] # noqa: F401
918+
except ModuleNotFoundError:
919+
pass
920+
else:
921+
@pytest.hookimpl(wrapper=True)
922+
def pytest_xdist_auto_num_workers(config: pytest.Config) -> Generator[None, int, int]:
923+
"""determine how many workers to use based on how many tests were selected in the test explorer"""
924+
return min((yield), len(config.option.file_or_dir))

0 commit comments

Comments
 (0)