Package: testcompose
TestcomposeTestcompose- A clean and better way to test your Python containerized applications.Testcomposeprovides 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 docker compose kind of functionality with the extra benefit of being able to fully control the containers from test codes.This is inspired by thetestcontainers-pythonproject and goes further to add a few additional functionalities to improve software integration testing while allowing the engineer to control every aspect of the test.Install testcompose using pip:$pipinstalltestcomposetestcompose requires Python 3.7+.Using a config file. See theQuickstartfor other options# Testcompose include a cli utility to help create a quickstart config file that should be update to suit the needs of the user.# Create a config file by running the commandtestcomposegenerate-template--help# shows the help and exit.# To generate template config for an app and a db combination, run the commandtestcomposegenerate-template--componentdb--componentapp# The above command ouputs to stdout. To output to a file, include a filepath as belowtestcomposegenerate-template--componentdb--componentapp--template-filesome-valid-file-location.yamlA sample of the config file is represented below:services:-name:databaseimage:"postgres:13"command:""environment:POSTGRES_USER:postgresPOSTGRES_DB:postgresPOSTGRES_PASSWORD:passwordexposed_ports:-5432log_wait_parameters:log_line_regex:"databasesystemisreadytoacceptconnections"wait_timeout_ms:30000poll_interval_ms:2000-name:applicationimage:"python:3.9"command:"/bin/bash-x/run_app.sh"environment:DB_URL:"${database.postgres_user}:${database.postgres_password}@${database.container_hostname}:5432/${database.postgres_db}"volumes:-host:"docker-test-files/run_app.sh"container:"/run_app.sh"mode:"ro"source:"filesystem"-host:"docker-test-files/app.py"container:"/app.py"mode:"ro"source:"filesystem"exposed_ports:-"8000"log_wait_parameters:log_line_regex:".*Applicationstartupcomplete.*"wait_timeout_ms:45000poll_interval_ms:2000http_wait_parameters:http_port:8000response_status_code:200end_point:"/ping"startup_delay_time_ms:30000use_https":falsedepends_on:-databaseVerify it as follows:importjsonfromtypingimportAny,DictfromrequestsimportResponse,getfromtestcompose.configs.service_configimportConfigfromtestcompose.models.bootstrap.container_serviceimportContainerServicesfromtestcompose.models.container.running_containerimportRunningContainerfromtestcompose.run_containersimportRunContainersconfig_services:ContainerServices=TestConfigParser.parse_config(file_name='some-config.yaml')running_config:Config=Config(test_services=config_services)withRunContainers(config_services=config_services,ranked_services=running_config.ranked_config_services,)asrunner:assertrunnerapp_container_srv_name="application"app_service:RunningContainer=runner.running_containers[app_container_srv_name]app_env_vars:Dict[str,Any]=app_service.config_environment_variablesmapped_port=app_service.generic_container.get_exposed_port("8000")print(app_env_vars)app_host=app_service.generic_container.get_container_host_ip()assertapp_env_varsassertmapped_portassertapp_hostresponse:Response=get(url=f"http://{app_host}:{int(mapped_port)}/version")assertresponseassertresponse.status_code==200assertresponse.textassertisinstance(json.loads(response.text),dict)DocumentationQuickstartSpecial-VariablesFull-Doc