🧪 The support crew for your test bench
Project description
KloudKIT TestShed
KloudKIT TestShed is a pytest plugin that streamlines integration tests with Docker
containers and Playwright—handling setup, execution, and teardown so you can focus on
writing effective tests.
Features
- Automated Docker management: Spin up and control containers from tests.
- Playwright integration: Run browser tests in isolated Docker environments.
- Configurable via markers & CLI: Tune environments per test or suite.
- Automatic resource cleanup: Ensures a clean state after tests.
Installation
pip install testshed
Usage
Docker container testing
TestShed provides fixtures to manage containers inside your tests.
High-level shed fixtures
Use the shed fixture for smart container management with configurable defaults:
import pytest
from kloudkit.testshed.docker import Container, HttpProbe
class MyAppContainer(Container):
DEFAULT_USER = "app"
@pytest.fixture(scope="session")
def shed_container_defaults():
"""Override this fixture to set project-specific defaults."""
return {
"container_class": MyAppContainer,
"envs": {"APP_PORT": 3000},
"probe": HttpProbe(port=3000, endpoint="/health"),
}
def test_my_app(shed):
# Uses your configured defaults automatically
assert shed.execute("whoami") == "app"
@shed_env(DEBUG="true")
def test_my_app_with_debug(shed):
# New container with override, merged with defaults
assert shed.execute("echo $DEBUG") == "true"
assert shed.execute("echo $APP_PORT") == "3000"
You can also use the factory directly:
def test_custom_setup(shed_factory):
container = shed_factory(envs={"CUSTOM_VAR": "value"})
# ... test logic ...
Basic Docker container
For a lower-level API, use the docker_sidecar fixture to create containers:
import pytest
def test_my_docker_app(docker_sidecar):
# Launch a simple Nginx container
nginx = docker_sidecar("nginx:latest", publish=[(8080, 80)])
# Execute a command inside the container
assert "nginx version" in nginx.execute(["nginx", "-v"])
# Access the container's IP
print(f"Nginx container IP: {nginx.ip()}")
# Interact with the file system
assert "/usr/share/nginx/html" in nginx.fs.ls("/usr/share/nginx")
Configure containers with decorators
Configure containers using pytest markers/decorators:
@shed_config(**kwargs): Generic container args.@shed_env(**envs): Environment variables.@shed_volumes(*mounts): Volume mounts as(source, dest)orInlineVolume.
from kloudkit.testshed.docker import InlineVolume
@shed_env(MY_ENV_VAR="hello")
@shed_volumes(
("/path/to/host/data", "/app/data:ro"),
InlineVolume("/app/config.txt", "any content you want", mode=0o644),
)
def test_configured_docker_app(docker_sidecar):
app = docker_sidecar("my-custom-app:latest")
# ... test logic ...
Playwright browser testing
Get a Playwright browser instance running in Docker via playwright_browser:
def test_example_website(playwright_browser):
page = playwright_browser.new_page()
page.goto("http://example.com")
assert "Example Domain" in page.title()
# ... more Playwright test logic ...
Command-line options
TestShed extends pytest with options to control the Docker environment:
--shed: Enable TestShed for the current test suite (default: disabled).--shed-image IMAGE: Base image (e.g.,ghcr.io/acme/app).--shed-tag TAG|SHA: Image tag or digest (default:tests).--shed-build-context DIR: Docker build context (default:pytest.inidirectory).--shed-require-local-image: Fail if image isn’t present locally (no build/pull).--shed-rebuild: Force rebuilding the test image.--shed-network NAME: Docker network (default:testshed-network).--shed-skip-bootstrap: Skip Docker bootstrapping (useful for unit tests).
[!NOTE] When TestShed is installed globally, you must explicitly enable it per suite with
--shed. This prevents it from configuring Docker in projects that don’t use it.
Examples
# Enable TestShed for your suite
pytest --shed --shed-image my-test-image --shed-rebuild
# Run tests without TestShed (default)
pytest
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file testshed-0.0.1.tar.gz.
File metadata
- Download URL: testshed-0.0.1.tar.gz
- Upload date:
- Size: 16.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c242827c46b087184a4247d0ba3ceb1b298e54898235c814467f0463729b6494
|
|
| MD5 |
64c9fa281ca5ab36eddd9761c8873685
|
|
| BLAKE2b-256 |
ff7b074904662578a63b25375690fac2adfae5f9bfeebe04aa6dd53b50be468b
|
Provenance
The following attestation bundles were made for testshed-0.0.1.tar.gz:
Publisher:
publish.yaml on kloudkit/testshed
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
testshed-0.0.1.tar.gz -
Subject digest:
c242827c46b087184a4247d0ba3ceb1b298e54898235c814467f0463729b6494 - Sigstore transparency entry: 524085818
- Sigstore integration time:
-
Permalink:
kloudkit/testshed@6ece08992e04cce52d15b7aca77544054d51141b -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/kloudkit
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@6ece08992e04cce52d15b7aca77544054d51141b -
Trigger Event:
release
-
Statement type:
File details
Details for the file testshed-0.0.1-py3-none-any.whl.
File metadata
- Download URL: testshed-0.0.1-py3-none-any.whl
- Upload date:
- Size: 22.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d691d36df0dcce50006a8286f148622f4178f49c6e29b90ffef2bdba2511b7fc
|
|
| MD5 |
605eef2ad6d290e2a049838f4bdae9ae
|
|
| BLAKE2b-256 |
e9be7aa18b79f2b986c3aeafdedb03ac0777fb1ddf2868a9c9b819a2b63446f9
|
Provenance
The following attestation bundles were made for testshed-0.0.1-py3-none-any.whl:
Publisher:
publish.yaml on kloudkit/testshed
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
testshed-0.0.1-py3-none-any.whl -
Subject digest:
d691d36df0dcce50006a8286f148622f4178f49c6e29b90ffef2bdba2511b7fc - Sigstore transparency entry: 524085824
- Sigstore integration time:
-
Permalink:
kloudkit/testshed@6ece08992e04cce52d15b7aca77544054d51141b -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/kloudkit
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@6ece08992e04cce52d15b7aca77544054d51141b -
Trigger Event:
release
-
Statement type: