Skip to main content
Latest version on Pypi: ? Supported Python versions: ? Build status (travis.com): ? Build status (circleci.com): ? Test coverage: ? %

This package was inspired by others, but after trying to make heads and tails of them when faced with bugs, I ended-up finding simpler to start over.

Using dockerfixtures with pytest

To spawn a container in your tests, proceed as follow:

import docker
from dockerfixtures import image, container
import pytest

@pytest.fixture(scope='session')
def docker_client():
     return docker.from_env()

@pytest.fixture(scope='session')
def pg_image() -> image.Image:
    return image.Image('postgres', tags='12')

@pytest.fixture(scope='function')
def pg_container(docker_client: docker.client.DockerClient,
                 pg_image: image.Image) -> container.Container:
    yield from container.fixture(docker_client, some_image)

# If you don't need to reuse the image

@pytest.fixture(scope='session')
def pg_container(docker_client) -> container.Container:
    some_image = image.Image('postgres', tags='12')
    yield from container.fixture(docker_client, some_image)

Why not a pytest plugin ?

Other implementation of this have been provinding a pytest plugin, so you might wonder why this one doesn’t ?

First reason is I have not looked into it that much, yet.

But anyhow, you would still need to import the dockerfixtures.image module. So I am not very sure what the benefits would be ?

Also I found those plugins to provide somewhat bizarre API, for example to define the fixtures’ scope. I haven’t looked into why they do that, yet. Here there are no surprises, a container fixture looks like any other fixture.

Pytest plugins are global: they have to be imported in your top-level conftest.py (see note). I think it is good practice to keep your tests properly partitioned based on their external dependencies. It can help split workload if the need arises. In a collaborative environment, having to import dockerfixtures, may help prevent breaking that partitioning during reviews.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dockerfixtures-0.2.4-py2.py3-none-any.whl (19.6 kB view details)

Uploaded Python 2Python 3

File details

Details for the file dockerfixtures-0.2.4-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for dockerfixtures-0.2.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 12b5328fa4da384766127456e64053a108e197f250102d5dfe6e72ae584a7e48
MD5 4d44b5a65771829ac28886a010557e6d
BLAKE2b-256 adf7c4cebccf441c63386809d58abbf9d9371546f6542b0711e7cc5bad4c1e7f

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.4 This release

1 file

0.2.3

1 file

0.2.2

1 file

0.2.0

1 file

0.1.0

1 file

0.0.0

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page