Skip to content

Commit

Permalink
test(conftest): ensure that pytest_sessionstart hook runs once (#669)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkniewallner committed Apr 8, 2024
1 parent caa4e43 commit 81a0964
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ warn_unreachable = true
pretty = true
show_error_codes = true

[[tool.mypy.overrides]]
module = ["xdist.*"]
ignore_missing_imports = true

[tool.deptry]
extend_exclude = [
"docs",
Expand Down
10 changes: 9 additions & 1 deletion tests/functional/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@
from pathlib import Path

import pytest
import xdist

from tests.functional.utils import DEPTRY_WHEEL_DIRECTORY
from tests.utils import PDMVenvFactory, PipVenvFactory, PoetryVenvFactory


def pytest_sessionstart() -> None:
def pytest_sessionstart(session: pytest.Session) -> None:
# When running the tests on multiple workers with pytest-xdist, the hook will be run several times:
# - once from "master" node, when test suite starts
# - X times (where X is the number of workers), when tests start in each worker
# We only want to run the hook once, so we explicitly skip the hook if running on a pytest-xdist worker.
if xdist.is_xdist_worker(session):
return None

deptry_wheel_path = Path(DEPTRY_WHEEL_DIRECTORY)

print(f"Building `deptry` wheel in {deptry_wheel_path} to use it on functional tests...") # noqa: T201
Expand Down

0 comments on commit 81a0964

Please sign in to comment.