Skip to content

Commit

Permalink
Fix requirement for docker engine for test runs (#2383)
Browse files Browse the repository at this point in the history
* Fix requirement for docker engine for test runs

Co-authored-by: Michael Adkins <[email protected]>
Co-authored-by: Chris Guidry <[email protected]>
  • Loading branch information
chrisguidry and zanieb authored Jul 20, 2022
1 parent f69b442 commit e0c6f02
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions tests/fixtures/docker.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import sys
from contextlib import contextmanager
from typing import Generator

import pytest
Expand All @@ -19,12 +21,24 @@


@pytest.fixture(scope="session")
def docker() -> Generator[DockerClient, None, None]:
with docker_client() as client:
yield client
def docker(worker_id: str) -> Generator[DockerClient, None, None]:
context = docker_client()
try:
client = context.__enter__()
except Exception as exc:
raise RuntimeError(
"Failed to create Docker client. Exclude tests that require Docker with "
"'--exclude-service docker'."
) from exc

try:
with cleanup_all_new_docker_objects(client, worker_id):
yield client
finally:
context.__exit__(*sys.exc_info())


@pytest.fixture(scope="session", autouse=True)
@contextmanager
def cleanup_all_new_docker_objects(docker: DockerClient, worker_id: str):
IMAGE_LABELS["io.prefect.test-worker"] = worker_id
CONTAINER_LABELS["io.prefect.test-worker"] = worker_id
Expand Down

0 comments on commit e0c6f02

Please sign in to comment.