{"id":21801,"library":"pytest-container","title":"pytest-container","description":"Pytest fixtures for writing container-based tests with support for OCI containers (Docker/Podman). Version 0.4.4 provides decorators and fixtures to manage container lifecycle. Active development, monthly releases.","status":"active","version":"0.4.4","language":"python","source_language":"en","source_url":"https://github.com/dcermak/pytest_container","tags":["pytest","container","docker","podman","testing"],"install":[{"cmd":"pip install pytest-container","lang":"bash","label":"pip install"}],"dependencies":[{"reason":"Core test runner","package":"pytest","optional":false},{"reason":"Container image derivation logic","package":"container-derivation","optional":false},{"reason":"Docker SDK (optional if using podman)","package":"docker","optional":true}],"imports":[{"note":"container fixture is at top-level","wrong":"from pytest_container.fixtures import container","symbol":"container","correct":"from pytest_container import container"},{"note":"","wrong":"","symbol":"DerivedContainer","correct":"from pytest_container import DerivedContainer"}],"quickstart":{"code":"from pytest_container import container, DerivedContainer\n\ndef test_container(container):\n    # container is a pytest fixture that starts a container\n    # inspect container object\n    assert container.connection.run(\"echo hello\").stdout.strip() == \"hello\"\n\n# Define custom container image\nclass TestWithCustomImage:\n    CONTAINER_IMAGE = DerivedContainer(\n        base=\"registry.opensuse.org/opensuse/tumbleweed:latest\",\n        containerfile=\"\"\"\nRUN zypper -n in python3\n        \"\"\"\n    )\n    def test_custom(self, container):\n        assert container.connection.run(\"python3 --version\").rc == 0","lang":"python","description":"Basic usage: use the container fixture or define a custom DerivedContainer class."},"warnings":[{"fix":"Add `from pytest_container import container` at the top of your test file.","message":"Version 0.4.x changed the fixture from `container` to require explicit import. Old code using `pytest_container` as a plugin may break if fixture is not imported.","severity":"breaking","affected_versions":"<0.4.0"},{"fix":"Define a `CONTAINER_IMAGE` class attribute or use `container` fixture with a parametrized image.","message":"The `container` fixture works only if the test class has a `CONTAINER_IMAGE` attribute or uses `@pytest.mark.parametrize`. Otherwise, the fixture raises an error.","severity":"gotcha","affected_versions":"all"},{"fix":"Replace `container_request` with `container` in your test functions.","message":"The `container_request` fixture is deprecated in 0.4.x. Use the `container` fixture instead.","severity":"deprecated","affected_versions":">=0.4.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Add `from pytest_container import container` at the top of your test file.","cause":"The `container` fixture is not automatically injected; it must be imported.","error":"AttributeError: module 'pytest_container' has no attribute 'container'"},{"fix":"Ensure pytest-container is installed (`pip install pytest-container`) and import the fixture: `from pytest_container import container`.","cause":"The `container` fixture is not available because it hasn't been imported or the plugin not installed.","error":"Fixture 'container' not found"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}