Skip to content

iangkent/pytest-containers

Repository files navigation

pytest-containers

PyPI Version Python Versions Build Status

A pytest plugin for docker and kubernetes fixtures. The plugin provides a framework for testing docker container images.

This plugin enables you to test code run in containers that relies on docker resources (container, volume, secret, network, ....). It allows you to specify fixtures for docker resources.

The main interface provided by this plugin is a set of fixtures and 'fixture factories'.

Features

Requirements

Installation

You can install "pytest-containers" via pip from PyPI:

pip install pytest-containers

Or include it as a dependency on setup.py or a requirements.txt file, whatever you prefer.

Usage

The following tests demonstrate how to use the fixtures provided by this plugin.

# test_container.py
def test_is_healthy(container):
    assert container.status == 'running'
...

Fixtures

docker_client

The docker_client fixture returns an instance of the official docker client.

def test_docker_version(docker_client):
    res = docker_client.version() 
    assert 'GoVersion' in res
    assert 'Version' in res

container

The container fixture returns an instance of Container.

def test_container(container):
    assert container.status == 'running'

client_container

The client container fixture returns an instance of Container connected to another container.

def test_client_container(container, client_container):
    assert container.status == 'running'
    assert client_container.status == 'running'

network

The container fixuture returns an instance of Network.

def test_default_network(network):
    assert network.name == 'bridge'
    assert network.attrs['Options']['com.docker.network.bridge.default_bridge' == 'true'

image

The container fixuture returns an instance of Image.

def test_image(image):
    assert image is not None

Read the full documentation to see everything you can do.

Contributing

Contributions are very welcome. Tests can be run with tox, please ensure the coverage at least stays the same before you submit a pull request.

License

Distributed under the terms of the Apache Software License 2.0 license, "pytest-containers" is free and open source software

Issues

If you encounter any problems, please file an issue along with a detailed description.

Similar Projects

About

A pytest plugin that provides docker and kubernetes fixtures.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published