Skip to content

Commit 3e4781a

Browse files
Liora Milbaumnejch
Liora Milbaum
authored andcommitted
refactor: pytest-docker fixtures
1 parent 124abab commit 3e4781a

File tree

3 files changed

+31
-25
lines changed

3 files changed

+31
-25
lines changed

tests/functional/conftest.py

+1-25
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import gitlab
1313
import gitlab.base
1414
from tests.functional import helpers
15+
from tests.functional.fixtures.docker import * # noqa
1516

1617
SLEEP_TIME = 10
1718

@@ -34,11 +35,6 @@ def gitlab_version(gl) -> GitlabVersion:
3435
return GitlabVersion(major=major, minor=minor, patch=patch, revision=revision)
3536

3637

37-
@pytest.fixture(scope="session")
38-
def docker_compose_command():
39-
return "docker compose"
40-
41-
4238
@pytest.fixture(scope="session")
4339
def fixture_dir(test_dir) -> pathlib.Path:
4440
return test_dir / "functional" / "fixtures"
@@ -160,26 +156,6 @@ def temp_dir() -> pathlib.Path:
160156
return pathlib.Path(tempfile.gettempdir())
161157

162158

163-
@pytest.fixture(scope="session")
164-
def docker_compose_file(fixture_dir):
165-
return fixture_dir / "docker-compose.yml"
166-
167-
168-
@pytest.fixture(scope="session")
169-
def docker_compose_project_name():
170-
"""Set a consistent project name to enable optional reuse of containers."""
171-
return "pytest-python-gitlab"
172-
173-
174-
@pytest.fixture(scope="session")
175-
def docker_cleanup(request):
176-
"""Conditionally keep containers around by overriding the cleanup command."""
177-
if request.config.getoption("--keep-containers"):
178-
# Print version and exit.
179-
return "-v"
180-
return "down -v"
181-
182-
183159
@pytest.fixture(scope="session")
184160
def check_is_alive():
185161
"""

tests/functional/fixtures/__init__.py

Whitespace-only changes.

tests/functional/fixtures/docker.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""
2+
pytest-docker fixture overrides.
3+
See https://github.com/avast/pytest-docker#available-fixtures.
4+
"""
5+
import pytest
6+
7+
8+
@pytest.fixture(scope="session")
9+
def docker_compose_command():
10+
return "docker compose"
11+
12+
13+
@pytest.fixture(scope="session")
14+
def docker_compose_project_name():
15+
"""Set a consistent project name to enable optional reuse of containers."""
16+
return "pytest-python-gitlab"
17+
18+
19+
@pytest.fixture(scope="session")
20+
def docker_compose_file(fixture_dir):
21+
return fixture_dir / "docker-compose.yml"
22+
23+
24+
@pytest.fixture(scope="session")
25+
def docker_cleanup(request):
26+
"""Conditionally keep containers around by overriding the cleanup command."""
27+
if request.config.getoption("--keep-containers"):
28+
# Print version and exit.
29+
return "-v"
30+
return "down -v"

0 commit comments

Comments
 (0)