Skip to main content
https://github.com/gtmanfred/teststack/workflows/Tests/badge.svg https://img.shields.io/codecov/c/github/gtmanfred/teststack https://img.shields.io/pypi/v/teststack https://img.shields.io/pypi/l/teststack https://img.shields.io/pypi/dm/teststack https://readthedocs.org/projects/teststack/badge?version=latest&style=flat

Test an application with infrastructure.

teststack.toml

[tests.steps]
ping = "ping -c4 8.8.8.8"
env = "env"
raw = "{posargs}"

[services.database]
image = "postgres:12"

[services.database.ports]
"5432/tcp" = ""

[services.database.environment]
POSTGRES_USER = "bebop"
POSTGRES_PASSWORD = "secret"
POSTGRES_DB = "bebop"

[services.database.export]
SQLALCHEMY_DATABASE_URI = "postgresql://{POSTGRES_USER}:{POSTGRES_PASSWORD}@{HOST}:{PORT;5432/tcp}/{POSTGRES_DB}"
POSTGRES_MAIN_USER = "{POSTGRES_USER}"
POSTGRES_MAIN_PASSWORD = "{POSTGRES_PASSWORD}"
POSTGRES_MAIN_HOST = "{HOST}"
POSTGRES_MAIN_RDS_HOST = "{HOST}"
POSTGRES_MAIN_PORT = "{PORT;5432/tcp}"
POSTGRES_MAIN_DBNAME = "{POSTGRES_DB}"

There are two main sections: tests and services.

The test section is for information about the docker container that is going to be used for testing. It renders the Dockerfile.j2, and injects environment variables for customization. The tests.steps section specifies which steps should be run on a test machine. Any unprocessed commandline arguments that are passed into teststack are stuck into commands as posargs.

teststack render
teststack build
teststack run -s raw -- pytest -k mytest
teststack stop

The services section specifies the services that need to be started along side a test container. In this example, a postgres container is started. Then the ports specify which ports need to be exposed, so 5432/tcp. And what environment variables should be passed to the service docker container when starting up, so that it can be configured. In this case, we set the username, password and db for the database. The three commands around the services are start, stop and restart, they do what they say.

teststack start
teststack stop
teststack restart

Everything that is set in the environment section is available when exporting. The other special variables that are made available is the HOST of the docker container. By default, the env command exports localhost for the {HOST} variable. And then the port that is exported has the number appended after a semicolon. So if you have specified 5432/tcp as a port for a service container, the variable {PORT;5432/tcp} will be made available for exporting, or to add to connection strings.

If however, the env is being used to start a test container (like run does) the HOST variable will be the default docker network IPAddress of the container, and the port will be just the port, and not adapted to the forwarding port on the Host network.

If you choose to run tests locally, instead of in the tests container, you can export the environment variables for the stack and source them or put them in a file for something like vscode to read.

$ source <(teststack env)
$ teststack env --no-export > .env

Metadata

Release files for teststack 0.16.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for teststack 0.16.1
File Size Uploaded Provenance
teststack-0.16.1.tar.gz 62.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for teststack 0.16.1
File Interpreter ABI Platform
teststack-0.16.1-py3-none-any.whl Python 3 none any Details

Total release size: 83.8 kB

Release files / teststack-0.16.1.tar.gz

Download URL teststack-0.16.1.tar.gz
Size 62.2 kB
Tags Source
SHA-256 checksum
How to use checksums
d3d95609aa130156ed90ccc9b8c999fe55ea60eb92475483984d9ad6372ace3e
BLAKE2b-256 checksum
How to use checksums
db266df1d1f37138bbe541c9815d364b5a18dd8e480c881fe3266887c64f1134
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / teststack-0.16.1-py3-none-any.whl

Download URL teststack-0.16.1-py3-none-any.whl
Size 21.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b858572e1eb0446e1d285253184af69f9bb6208cbfd84a7dc2451e1365cf8e75
BLAKE2b-256 checksum
How to use checksums
789cc7645b4ad8f432d2c35c446666ffa7f5ca7f623b1a9e92fb67275118dbd2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Security for teststack 0.16.1

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.16.1 This release

2 release files No provenance

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