Skip to content

Commit

Permalink
add hook to the pytest vscode plugin to determine how many xdist work…
Browse files Browse the repository at this point in the history
…ers to use based on how many tests are selected
  • Loading branch information
DetachHead committed Jun 2, 2024
1 parent 6d88415 commit 00f953b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions python_files/vscode_pytest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
import sys
import traceback


from pluggy import Result
import pytest

script_dir = pathlib.Path(__file__).parent.parent
sys.path.append(os.fspath(script_dir))
sys.path.append(os.fspath(script_dir / "lib" / "python"))

from testing_tools import socket_manager # noqa: E402
from typing import Any, Dict, List, Optional, Union, TypedDict, Literal # noqa: E402
from typing import Any, Dict, Generator, List, Optional, Union, TypedDict, Literal # noqa: E402


class TestData(TypedDict):
Expand Down Expand Up @@ -881,3 +881,9 @@ def send_post_request(
f"Plugin error, exception thrown while attempting to send data[vscode-pytest]: {error} \n[vscode-pytest] data: \n{data}\n",
file=sys.stderr,
)


@pytest.hookimpl(hookwrapper=True)
def pytest_xdist_auto_num_workers(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))

0 comments on commit 00f953b

Please sign in to comment.