Giter VIP home page Giter VIP logo

sagar2366 / testcontainers-python Goto Github PK

View Code? Open in Web Editor NEW

This project forked from testcontainers/testcontainers-python

0.0 1.0 0.0 524 KB

Testcontainers is a Python library that providing a friendly API to run Docker container. It is designed to create runtime environment to use during your automatic tests.

Home Page: https://testcontainers-python.readthedocs.io/en/latest/

License: Apache License 2.0

Python 98.63% Makefile 0.98% Dockerfile 0.38%

testcontainers-python's Introduction

testcontainers-python

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
  • Neo4j container
  • OracleDb container
  • PostgreSQL Db container
  • ClickHouse container
  • Microsoft SQL Server container
  • Generic docker containers
  • ArangoDB container
  • LocalStack
  • RabbitMQ
  • Keycloak
  • Azurite container

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

>>> 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.

Usage within Docker (e.g., in a CI)

When trying to launch a testcontainer from within a Docker container two things have to be provided:

  1. The container has to provide a docker client installation. Either use an image that has docker pre-installed (e.g. the official docker images) or install the client from within the Dockerfile specification.
  2. The container has to have access to the docker daemon which can be achieved by mounting /var/run/docker.sock or setting the DOCKER_HOST environment variable as part of your docker run command.

Setting up a development environment

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 -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, 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.

Contributing a new container

You can contribute a new container in three steps:

  1. Create a new module at testcontainers/[my fancy container].py that implements the new functionality.
  2. Create a new test module at tests/test_[my fancy container].py that tests the new functionality.
  3. Add [my fancy container] to the list of test components in the GitHub Action configuration at .github/workflows/main.yml.

testcontainers-python's People

Contributors

gospodinkot avatar tillahoffmann avatar sergeypirogov avatar timbmg avatar annabaas avatar tuvshuud avatar yakimka avatar pffijt avatar dstape avatar eastlondoner avatar jmorales4 avatar kieranlea avatar romank0 avatar skirino avatar lippertto avatar t0ch1k avatar datokenizer avatar aloosley avatar ahaeger avatar ysde avatar ash1425 avatar dlmiddlecote avatar denismakogon avatar fsonntag avatar imflog avatar francislfg avatar razerm avatar gfernie avatar walles avatar kvelichko avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.