Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xdist fixes #23791

Merged
merged 3 commits into from
Jul 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions python_files/vscode_pytest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
)

import pytest
from pluggy import Result

script_dir = pathlib.Path(__file__).parent.parent
sys.path.append(os.fspath(script_dir))
Expand Down Expand Up @@ -889,11 +890,25 @@ def send_post_request(

class DeferPlugin:
@pytest.hookimpl(hookwrapper=True)
def pytest_xdist_auto_num_workers(self, config: pytest.Config) -> Generator[None, int, int]:
def pytest_xdist_auto_num_workers(
self, config: pytest.Config
) -> Generator[None, Result[int], None]:
"""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))
outcome = yield
result = min(outcome.get_result(), len(config.option.file_or_dir))
if result == 1:
result = 0
outcome.force_result(result)


def pytest_plugin_registered(plugin: object, manager: pytest.PytestPluginManager):
if manager.hasplugin("xdist") and not isinstance(plugin, DeferPlugin):
manager.register(DeferPlugin())
plugin_name = "vscode_xdist"
if (
# only register the plugin if xdist is enabled:
manager.hasplugin("xdist")
# prevent infinite recursion:
and not isinstance(plugin, DeferPlugin)
# prevent this plugin from being registered multiple times:
and not manager.hasplugin(plugin_name)
):
manager.register(DeferPlugin(), name=plugin_name)
Loading