|
19 | 19 | )
|
20 | 20 |
|
21 | 21 | import pytest
|
| 22 | +from pluggy import Result |
22 | 23 |
|
23 | 24 | script_dir = pathlib.Path(__file__).parent.parent
|
24 | 25 | sys.path.append(os.fspath(script_dir))
|
@@ -889,11 +890,25 @@ def send_post_request(
|
889 | 890 |
|
890 | 891 | class DeferPlugin:
|
891 | 892 | @pytest.hookimpl(hookwrapper=True)
|
892 |
| - def pytest_xdist_auto_num_workers(self, config: pytest.Config) -> Generator[None, int, int]: |
| 893 | + def pytest_xdist_auto_num_workers( |
| 894 | + self, config: pytest.Config |
| 895 | + ) -> Generator[None, Result[int], None]: |
893 | 896 | """Determine how many workers to use based on how many tests were selected in the test explorer."""
|
894 |
| - return min((yield), len(config.option.file_or_dir)) |
| 897 | + outcome = yield |
| 898 | + result = min(outcome.get_result(), len(config.option.file_or_dir)) |
| 899 | + if result == 1: |
| 900 | + result = 0 |
| 901 | + outcome.force_result(result) |
895 | 902 |
|
896 | 903 |
|
897 | 904 | def pytest_plugin_registered(plugin: object, manager: pytest.PytestPluginManager):
|
898 |
| - if manager.hasplugin("xdist") and not isinstance(plugin, DeferPlugin): |
899 |
| - manager.register(DeferPlugin()) |
| 905 | + plugin_name = "vscode_xdist" |
| 906 | + if ( |
| 907 | + # only register the plugin if xdist is enabled: |
| 908 | + manager.hasplugin("xdist") |
| 909 | + # prevent infinite recursion: |
| 910 | + and not isinstance(plugin, DeferPlugin) |
| 911 | + # prevent this plugin from being registered multiple times: |
| 912 | + and not manager.hasplugin(plugin_name) |
| 913 | + ): |
| 914 | + manager.register(DeferPlugin(), name=plugin_name) |
0 commit comments