Skip to content

Commit

Permalink
use a different method to conditionally register the `pytest_xdist_au…
Browse files Browse the repository at this point in the history
…to_num_workers` hook because the `pytest_configure` hook didn't work for some reason
  • Loading branch information
DetachHead committed Jun 18, 2024
1 parent 6277810 commit 50dd822
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions python_files/vscode_pytest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -914,15 +914,12 @@ def send_post_request(
)


def pytest_configure(config: pytest.Config):
if config.pluginmanager.hasplugin("xdist"):

class XdistHook:
@pytest.hookimpl(hookwrapper=True)
def pytest_xdist_auto_num_workers(
self, config: pytest.Config
) -> Generator[None, Result[int], int]:
"""determine how many workers to use based on how many tests were selected in the test explorer"""
return min((yield).get_result(), len(config.option.file_or_dir))

config.pluginmanager.register(XdistHook())
try:
import xdist
except ModuleNotFoundError:
pass
else:
@pytest.hookimpl(wrapper=True)
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))

0 comments on commit 50dd822

Please sign in to comment.