| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
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:
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]>>> from testcontainers.postgres import PostgresContainer
>>> import sqlalchemy
>>> postgres_container = PostgresContainer("postgres:9.5")
>>> with postgres_container as postgres:
... e = sqlalchemy.create_engine(postgres.get_connection_url())
... result = e.execute("select version()")
... version, = result.fetchone()
>>> version
'PostgreSQL 9.5...'The snippet above will spin up a Postgres 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.
When trying to launch a testcontainer from within a Docker container two things have to be provided:
We recommend you use a virtual environment for development. Note that a python version >=3.6 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 -sWe use pip-tools to resolve and manage dependencies. If you need to add a dependency to testcontainers or one of the extras, modify the setup.py as well as the requirements.in accordingly and then run pip install pip-tools followed by make requirements to update the requirements files.
You can contribute a new container in three steps:
| Back | FazBrowse Home | New Git URL |