Skip to main content

"Provide an easy way to perform integration testing with docker and python"

Project description

Testcompose

Testcompose

Testcompose - A clean and better way to test your Python containerized applications.

RunningTests Testcompose version


Testcompose provides an easy way of using docker containers for functional and integration testing. It allows for combination of more than one containers and allows for interactions with these containers from your test code without having to write extra scripts for such interactions. I.e providing a docke compose kind of functionality with the extra benefit of being abale to fully control the containers from test codes.

This is inspired by the testcontainers-python project and goes further to add a few additional functionality to imporve software integration testing while allowing the engineer control every aspect of the test.


Install testcompose using pip:

$ pip install testcompose

testcompose requires Python 3.7+.

Using a config file. See the Quickstart for other options

network:
  name: some_network_name
  auto_create: False
  use_random_network: True
services:
  - name: db1
    image: "postgres:13"
    auto_remove: True
    command: ""
    environment:
      POSTGRES_USER: postgres
      POSTGRES_DB: postgres
      POSTGRES_PASSWORD: a
    exposed_ports:
      - 5432
    volumes:
      - host: "data_volume"
        container: "/data"
        mode: "rw"
        source: "docker" # possible values are `docker` or `local`
    log_wait_parameters:
      log_line_regex: "database system is ready to accept connections"
      wait_timeout: 30
      poll_interval: 2

Verify it as follows:

from testcompose.parse_config import TestConfigParser
from testcompose.configs.service_config import Config
from testcompose.run_containers import RunContainers

my_test_service = TestConfigParser.parse_config(
    file_name='some-file-name'
)
my_config =  Config(test_services=my_test_service)
print(my_config.ranked_itest_config_services)

with RunContainers(
        services=running_config.ranked_itest_config_services
) as runner:
    # Interract with the running containers

    assert runner.containers

    # Use some special parameters of the running containers

    app_container = runner.extra_envs["app_container_config_name"]

    # Get the host port a certain exposed container port is mapped to
    mapped_port = app_container.get("DOCKER_PYTHON_MAPPED_PORTS", {}).get("port")

    # where `port` is the exposed port of the container

Documentation

Quickstart

Special-Variables

Full-Doc

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

testcompose-0.0.4.tar.gz (23.4 kB view hashes)

Uploaded Source

Built Distributions

testcompose-0.0.4-py3.9.egg (53.4 kB view hashes)

Uploaded Source

testcompose-0.0.4-py3-none-any.whl (27.0 kB view hashes)

Uploaded Python 3

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