Skip to main content

Manage the infrastructure for running tests against

Project description

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 https://img.shields.io/lgtm/grade/python/g/gtmanfred/teststack.svg?logo=lgtm&logoWidth=18

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

teststack-0.15.0.tar.gz (58.0 kB view details)

Uploaded Source

Built Distribution

teststack-0.15.0-py3-none-any.whl (21.4 kB view details)

Uploaded Python 3

File details

Details for the file teststack-0.15.0.tar.gz.

File metadata

  • Download URL: teststack-0.15.0.tar.gz
  • Upload date:
  • Size: 58.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for teststack-0.15.0.tar.gz
Algorithm Hash digest
SHA256 7745ecd81f2b6255046c69029201f86bd8a93146dfe54ad97b024cc612abffc7
MD5 4e96dae408cf84f9c9b8a4ba43199337
BLAKE2b-256 ab976f11a4804aafb3322b7642584b57be2f343750a5c9236995e0af4c57b044

See more details on using hashes here.

File details

Details for the file teststack-0.15.0-py3-none-any.whl.

File metadata

  • Download URL: teststack-0.15.0-py3-none-any.whl
  • Upload date:
  • Size: 21.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for teststack-0.15.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7a67f8e4f306964f70993258318cf5758068dbb49603f11ad93bc33a267f1103
MD5 f439f6114534b750386df97b2ac8cd9f
BLAKE2b-256 2eb3bb61fe382137fbc943b2b31078622cc3fef1b8d4c68402e03638f4c36707

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page