Skip to content
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
4 changes: 2 additions & 2 deletions test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ importlib-metadata==4.6.1
iniconfig==1.1.1
jsonschema==3.2.0
packaging>=21.0
paramiko==2.10.1
paramiko>=3.4.0
pluggy>=1.0.0
protobuf>=3.13.0,<7.0.0
py>=1.11.0
pycparser==2.20
PyNaCl==1.4.0
PyNaCl>=1.5
pyparsing==2.4.7
pyrsistent==0.18.0
pytest>=7.0.0,<8.0.0
Expand Down
43 changes: 43 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import docker
import pytest
from pytest_docker.plugin import DockerComposeExecutor, Services, containers_scope
import ydb
from ydb import issues

Expand Down Expand Up @@ -62,6 +63,48 @@ def docker_cleanup():
return ["down -v --remove-orphans"]


def _cleanup_docker_project(project_name):
docker_client = _docker_client()
project_filter = {"label": f"com.docker.compose.project={project_name}"}

for container in docker_client.containers.list(all=True, filters=project_filter):
container.remove(force=True, v=True)

for network in docker_client.networks.list(filters=project_filter):
network.remove()

for volume in docker_client.volumes.list(filters=project_filter):
volume.remove(force=True)


@pytest.fixture(scope=containers_scope)
def docker_services(
docker_compose_command,
docker_compose_file,
docker_compose_project_name,
docker_setup,
docker_cleanup,
):
"""Start compose services and clean them up without forking during teardown."""
docker_compose = DockerComposeExecutor(
docker_compose_command,
docker_compose_file,
docker_compose_project_name,
)

if docker_setup:
if isinstance(docker_setup, str):
docker_setup = [docker_setup]
for command in docker_setup:
docker_compose.execute(command)

try:
yield Services(docker_compose)
finally:
if docker_cleanup:
_cleanup_docker_project(docker_compose_project_name)


class DockerProject:
"""Compatibility wrapper for pytest-docker-compose docker_project fixture.

Expand Down
Loading