Install & Compatibility
Where this runs
tested against v0.4.4 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.684s · 32.4MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 2.9s · import 0.604s · 33MB
31MB installed
● package 31MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
container
✓ from pytest_container import container
✗ from pytest_container.fixtures import container
container fixture is at top-level
DerivedContainer
✓ from pytest_container import DerivedContainer
Basic usage: use the container fixture or define a custom DerivedContainer class.
from pytest_container import container, DerivedContainer
def test_container(container):
# container is a pytest fixture that starts a container
# inspect container object
assert container.connection.run("echo hello").stdout.strip() == "hello"
# Define custom container image
class TestWithCustomImage:
CONTAINER_IMAGE = DerivedContainer(
base="registry.opensuse.org/opensuse/tumbleweed:latest",
containerfile="""
RUN zypper -n in python3
"""
)
def test_custom(self, container):
assert container.connection.run("python3 --version").rc == 0
Errors
Common errors & fixes
AttributeError: module 'pytest_container' has no attribute 'container'
The `container` fixture is not automatically injected; it must be imported.
fixAdd `from pytest_container import container` at the top of your test file.
Fixture 'container' not found
The `container` fixture is not available because it hasn't been imported or the plugin not installed.
fixEnsure pytest-container is installed (`pip install pytest-container`) and import the fixture: `from pytest_container import container`.
Upgrade
Version history
0.4.4latest on PyPI · released Jun 30, 2025
Audit
Dependencies
pytestrequiredCore test runner
container-derivationrequiredContainer image derivation logic
dockeroptionalDocker SDK (optional if using podman)