pytest-multi-backend
Run one pytest suite against several interchangeable backends.
A “backend” is one way of running the system which the tests exercise. A suite might run against a real remote service, an in-memory fake of that service, and the same fake behind an HTTP server, and assert the same things about each. That is how a fake is kept honest.
Installation
pip install pytest-multi-backend
This requires Python 3.12+.
Usage
Backends are the members of an Enum. The member name, in lower case, is what --skip-backend takes to skip the backend. The member value is the ID which pytest shows for it.
backend_fixture makes a fixture which runs each test which uses it once per backend. Assign the fixture to a module-level name in a conftest.py for pytest to find it.
"""Run each test against the real service and against a fake."""
from collections.abc import Generator
from enum import Enum
import pytest
from pytest_multi_backend import backend_fixture
class Backend(Enum):
"""The ways of running the service under test."""
REAL = "Real service"
FAKE = "In memory fake"
def _setup_backend(
*,
backend: Backend,
request: pytest.FixtureRequest,
) -> Generator[None]:
"""Set a backend up, yield while the test runs, then tear it down.
Anything else the setup needs comes from
``request.getfixturevalue``.
"""
monkeypatch = request.getfixturevalue(argname="monkeypatch")
if backend is Backend.FAKE:
# Start the fake here, and point the code under test at it.
monkeypatch.setenv(name="SERVICE_URL", value="http://localhost:8080")
yield
# Stop the fake here.
return
monkeypatch.setenv(name="SERVICE_URL", value="https://example.com")
yield
fixture_backend = backend_fixture(
name="backend",
backends=list(Backend),
setup_for=_setup_backend,
)
A test which requests the fixture runs once per backend, and gets the backend it is running against:
"""A test which runs against each backend."""
from enum import Enum
def test_something(backend: Enum) -> None:
"""Assert the same thing about every backend."""
assert backend.value
Skipping backends
Give --skip-backend the lower case name of a backend to skip every test against it. Give it once per backend to skip.
$ pytest --skip-backend=real
Tests against a skipped backend are skipped, not deselected, so a run which skips a backend still reports the tests which would have used it. The setup function is not called for a skipped backend. Giving a name which no fixture has a backend for is an error, so a mistyped name does not silently run tests against a backend you meant to avoid.
Skipping marked tests
Give --skip-marker the name of a registered marker to skip every test which carries it. Give it once per marker to skip.
$ pytest --skip-marker=requires_docker
Unlike -m "not requires_docker", this skips rather than deselects, so the skipped tests are still reported. The marker must be registered in the markers setting, as --strict-markers requires, and giving an unregistered marker is an error.
Full documentation
See the full documentation.
Release files for pytest-multi-backend 2026.9.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pytest_multi_backend-2026.9.7.tar.gz | 151.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pytest_multi_backend-2026.9.7-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 161.1 kB
Release files / pytest_multi_backend-2026.9.7.tar.gz
| Download URL | pytest_multi_backend-2026.9.7.tar.gz |
|---|---|
| Size | 151.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
211cb2eb41b366a3b156a67b0bd26da08ce9c023c16a83de0da26b06520a3c3c
|
|
BLAKE2b-256 checksum How to use checksums |
3eaa83b9bdb46bb3400986766012fb9eefd0953546b109137360ae6e3863aaa6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 7, 2026.
Transparency logRelease files / pytest_multi_backend-2026.9.7-py3-none-any.whl
| Download URL | pytest_multi_backend-2026.9.7-py3-none-any.whl |
|---|---|
| Size | 10.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d5ec1c53539db7228589bedcad9f78420e74a682d5d1ca37fa1aaabdf80219c7
|
|
BLAKE2b-256 checksum How to use checksums |
0b3716f47df9be59dae0bdd7c0af14201cdf67de39807844d776d54666dcc9e3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 7, 2026.
Transparency log