Skip to content

Commit 743b8a9

Browse files
Merge pull request #2033 from VWS-Python/portable-tests
Change tests to not rely on location within repository
2 parents 5aff6af + ccdd96a commit 743b8a9

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

ci/custom_linters.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88
import yaml
99

1010

11-
def _ci_patterns() -> set[str]:
11+
def _ci_patterns(repository_root: Path) -> set[str]:
1212
"""
1313
Return the CI patterns given in the CI configuration file.
1414
"""
15-
repository_root = Path(__file__).parent.parent
1615
ci_file = repository_root / ".github" / "workflows" / "ci.yml"
1716
github_workflow_config = yaml.safe_load(ci_file.read_text())
1817
matrix = github_workflow_config["jobs"]["build"]["strategy"]["matrix"]
@@ -50,12 +49,12 @@ def _tests_from_pattern(
5049
return tests
5150

5251

53-
def test_ci_patterns_valid() -> None:
52+
def test_ci_patterns_valid(request: pytest.FixtureRequest) -> None:
5453
"""
5554
All of the CI patterns in the CI configuration match at least one test in
5655
the test suite.
5756
"""
58-
ci_patterns = _ci_patterns()
57+
ci_patterns = _ci_patterns(repository_root=request.config.rootpath)
5958

6059
for ci_pattern in ci_patterns:
6160
collect_only_result = pytest.main(
@@ -82,13 +81,14 @@ def test_ci_patterns_valid() -> None:
8281

8382
def test_tests_collected_once(
8483
capsys: pytest.CaptureFixture[str],
84+
request: pytest.FixtureRequest,
8585
) -> None:
8686
"""
8787
Each test in the test suite is collected exactly once.
8888
8989
This does not necessarily mean that they are run - they may be skipped.
9090
"""
91-
ci_patterns = _ci_patterns()
91+
ci_patterns = _ci_patterns(repository_root=request.config.rootpath)
9292
tests_to_patterns: dict[str, set[str]] = {}
9393

9494
for pattern in ci_patterns:

tests/mock_vws/test_docker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import uuid
88
from http import HTTPStatus
9-
from pathlib import Path
109
from typing import TYPE_CHECKING
1110

1211
import docker # type: ignore[import-untyped]
@@ -105,12 +104,13 @@ def fixture_custom_bridge_network() -> Iterator[Network]:
105104
def test_build_and_run(
106105
high_quality_image: io.BytesIO,
107106
custom_bridge_network: Network,
107+
request: pytest.FixtureRequest,
108108
) -> None:
109109
"""
110110
It is possible to build Docker images which combine to make a working mock
111111
application.
112112
"""
113-
repository_root = Path(__file__).parent.parent.parent
113+
repository_root = request.config.rootpath
114114
client = docker.from_env()
115115

116116
dockerfile = repository_root / "src/mock_vws/_flask_server/Dockerfile"

0 commit comments

Comments
 (0)