Skip to main content

Library provides lightweight, throwaway instances of common databases, Selenium web browsers, or anything else that can run in a Docker container

Project description

https://travis-ci.org/testcontainers/testcontainers-python.svg?branch=master https://img.shields.io/pypi/v/testcontainers.svg?style=flat-square https://readthedocs.org/projects/testcontainers-python/badge/?version=latest

Python port for testcontainers-java that allows using docker containers for functional and integration testing. Testcontainers-python provides capabilities to spin up docker containers (such as a database, Selenium web browser, or any other container) for testing.

Currently available features:

  • Selenium Grid containers

  • Selenium Standalone containers

  • MySql Db container

  • MariaDb container

  • OracleDb container

  • PostgreSQL Db container

  • Microsoft SQL Server container

  • Generic docker containers

Installation

The testcontainers package is available from PyPI, and it can be installed using pip. Depending on which containers are needed, you can specify additional dependencies as extras:

# Install without extras
pip install testcontainers
# Install with one or more extras
pip install testcontainers[mysql]
pip install testcontainers[mysql,oracle]

Basic usage

import sqlalchemy
from testcontainers.mysql import MySqlContainer

with MySqlContainer('mysql:5.7.17') as mysql:
    engine = sqlalchemy.create_engine(mysql.get_connection_url())
    version, = engine.execute("select version()").fetchone()
    print(version)  # 5.7.17

The snippet above will spin up a MySql database in a container. The get_connection_url() convenience method returns a sqlalchemy compatible url we use to connect to the database and retrieve the database version.

More extensive documentation can be found at Read The Docs.

Setting up a development environment

We recommend you use a virtual environment for development. Note that a python version >=3.5 is required. After setting up your virtual environment, you can install all dependencies and test the installation by running the following snippet.

pip install -r requirements/$(python -c 'import sys; print("%d.%d" % sys.version_info[:2])').txt
pytest -s

Adding requirements

We use pip-tools to resolve and manage dependencies. If you need to add a dependency to testcontainers or one of the extras, run pip install pip-tools followed by make requirements to update the requirements files.

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

testcontainers-3.0.3.tar.gz (13.1 kB view details)

Uploaded Source

File details

Details for the file testcontainers-3.0.3.tar.gz.

File metadata

  • Download URL: testcontainers-3.0.3.tar.gz
  • Upload date:
  • Size: 13.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.5.6

File hashes

Hashes for testcontainers-3.0.3.tar.gz
Algorithm Hash digest
SHA256 58235a82c3b4d18fd740bf7efd2df43f1e4f3ea5bdd3507a766b25c0b7d4eb09
MD5 ec0dd09bbc78e9fa976c0c2735e4d8b6
BLAKE2b-256 8f72bb057dae5eb57e910e8151b25569e443cbf178db98bc27769b3bf22f0e40

See more details on using hashes here.

Supported by

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