|
1 | | -import os.path |
| 1 | +import os |
| 2 | +from pathlib import Path |
2 | 3 | from typing import List |
3 | 4 |
|
4 | 5 | import pytest |
5 | 6 | from _pytest.fixtures import FixtureRequest |
6 | 7 | from _pytest.pytester import Pytester |
7 | 8 |
|
8 | | -HERE = os.path.dirname(os.path.abspath(__file__)) |
9 | 9 |
|
| 10 | +@pytest.fixture |
| 11 | +def tests_dir(pytester: Pytester) -> Path: |
| 12 | + dir = Path(pytester.path) / "tests" |
| 13 | + dir.mkdir() |
| 14 | + return dir |
| 15 | + |
| 16 | + |
| 17 | +@pytest.fixture(params=[[]]) |
| 18 | +def tests_dir_contents(tests_dir: Path, request: FixtureRequest) -> List[Path]: |
| 19 | + filenames: List[str] = request.param |
| 20 | + paths = [tests_dir / filename for filename in filenames] |
| 21 | + for path in paths: |
| 22 | + path.touch() |
| 23 | + |
| 24 | + return paths |
| 25 | + |
| 26 | + |
| 27 | +@pytest.mark.parametrize( |
| 28 | + ("tests_dir_contents", "effective_compose_file"), |
| 29 | + [ |
| 30 | + ( |
| 31 | + [ |
| 32 | + "compose.yaml", |
| 33 | + "compose.yml", |
| 34 | + "docker-compose.yaml", |
| 35 | + "docker-compose.yml", |
| 36 | + ], |
| 37 | + "compose.yaml", |
| 38 | + ), |
| 39 | + (["compose.yml", "docker-compose.yaml", "docker-compose.yml"], "compose.yml"), |
| 40 | + (["docker-compose.yaml", "docker-compose.yml"], "docker-compose.yaml"), |
| 41 | + (["docker-compose.yml"], "docker-compose.yml"), |
| 42 | + ([], "docker-compose.yml"), |
| 43 | + ], |
| 44 | + indirect=["tests_dir_contents"], |
| 45 | +) |
| 46 | +@pytest.mark.usefixtures("tests_dir_contents") |
| 47 | +def test_docker_compose_file( |
| 48 | + pytester: Pytester, |
| 49 | + effective_compose_file: str, |
| 50 | + tests_dir: Path, |
| 51 | +) -> None: |
| 52 | + pytester.makepyfile( |
| 53 | + f""" |
| 54 | + def test_docker_compose_file(docker_compose_file): |
| 55 | + assert docker_compose_file == "{tests_dir}/{effective_compose_file}" |
| 56 | + """ |
| 57 | + ) |
10 | 58 |
|
11 | | -def test_docker_compose_file(docker_compose_file: str) -> None: |
12 | | - assert docker_compose_file == os.path.join(HERE, "docker-compose.yml") |
| 59 | + result = pytester.runpytest() |
| 60 | + result.assert_outcomes(passed=1) |
13 | 61 |
|
14 | 62 |
|
15 | 63 | def test_docker_compose_project(docker_compose_project_name: str) -> None: |
|
0 commit comments