|
9 | 9 | import traceback
|
10 | 10 |
|
11 | 11 |
|
12 |
| -from pluggy import Result |
13 | 12 | import pytest
|
14 | 13 |
|
15 | 14 | script_dir = pathlib.Path(__file__).parent.parent
|
16 | 15 | sys.path.append(os.fspath(script_dir))
|
17 | 16 | sys.path.append(os.fspath(script_dir / "lib" / "python"))
|
18 | 17 | from testing_tools import socket_manager # noqa: E402
|
19 |
| -from typing import ( |
| 18 | +from typing import ( # noqa: E402 |
20 | 19 | Any,
|
21 | 20 | Dict,
|
22 | 21 | List,
|
|
25 | 24 | TypedDict,
|
26 | 25 | Literal,
|
27 | 26 | Generator,
|
28 |
| -) # noqa: E402 |
| 27 | +) |
29 | 28 |
|
30 | 29 |
|
31 | 30 | class TestData(TypedDict):
|
@@ -914,15 +913,12 @@ def send_post_request(
|
914 | 913 | )
|
915 | 914 |
|
916 | 915 |
|
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