Skip to content

Change tests to not rely on location within repository #2033

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

Merged
merged 1 commit into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
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
10 changes: 5 additions & 5 deletions ci/custom_linters.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
import yaml


def _ci_patterns() -> set[str]:
def _ci_patterns(repository_root: Path) -> set[str]:
"""
Return the CI patterns given in the CI configuration file.
"""
repository_root = Path(__file__).parent.parent
ci_file = repository_root / ".github" / "workflows" / "ci.yml"
github_workflow_config = yaml.safe_load(ci_file.read_text())
matrix = github_workflow_config["jobs"]["build"]["strategy"]["matrix"]
Expand Down Expand Up @@ -50,12 +49,12 @@ def _tests_from_pattern(
return tests


def test_ci_patterns_valid() -> None:
def test_ci_patterns_valid(request: pytest.FixtureRequest) -> None:
"""
All of the CI patterns in the CI configuration match at least one test in
the test suite.
"""
ci_patterns = _ci_patterns()
ci_patterns = _ci_patterns(repository_root=request.config.rootpath)

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

def test_tests_collected_once(
capsys: pytest.CaptureFixture[str],
request: pytest.FixtureRequest,
) -> None:
"""
Each test in the test suite is collected exactly once.

This does not necessarily mean that they are run - they may be skipped.
"""
ci_patterns = _ci_patterns()
ci_patterns = _ci_patterns(repository_root=request.config.rootpath)
tests_to_patterns: dict[str, set[str]] = {}

for pattern in ci_patterns:
Expand Down
4 changes: 2 additions & 2 deletions tests/mock_vws/test_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import uuid
from http import HTTPStatus
from pathlib import Path
from typing import TYPE_CHECKING

import docker # type: ignore[import-untyped]
Expand Down Expand Up @@ -105,12 +104,13 @@ def fixture_custom_bridge_network() -> Iterator[Network]:
def test_build_and_run(
high_quality_image: io.BytesIO,
custom_bridge_network: Network,
request: pytest.FixtureRequest,
) -> None:
"""
It is possible to build Docker images which combine to make a working mock
application.
"""
repository_root = Path(__file__).parent.parent.parent
repository_root = request.config.rootpath
client = docker.from_env()

dockerfile = repository_root / "src/mock_vws/_flask_server/Dockerfile"
Expand Down