Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

pytest plugin with fixtures for testing consul aware apps

Project Description


pytest-consul is a pytest plugin meant for being able to do integration and
unit testing against [Hashicorp's Consul](

This plugin is heavily influenced by the design of


$ pip install pytest-consul


When pytest-consul is installed, the fixtures available will ensure that an
actual local consul agent in bootstrap mode is running. The fixture object
contains a dictionary containing each of the exposed consul ports by name.

The `consul` fixture is session scoped. All tests using it will share catalog
and kv state.

def test_consul_thing(consul):
http_port = consul['http']
my_app.register_consul(('localhost', http_port))
resp = requests.get('http://localhost:{port}/v1/key/my-test-key'.format(
actual_value = base64.b64decode(resp.json()[0]['Value'])
assert actual_value == 'my-expected-value'

The `consul_clean` fixture is function scoped. If you want a clean consul state
for a given test, this fixture will provide it.


The consul agent takes a second or two to start up, even in bootstrap mode.
This makes these fixtures better for integration style tests, rather than unit
tests. Using the function scope `consul_clean` in particular is going to add
that additional latency to every single test which uses it. The flip side of
this is that using the session scope `consul` will not give you test isolation;
if your tests leave values in the kv store or catalog, it may affect any tests
that run after them.


pytest-consul adds the option `--consul-binary` to py.test, allowing you to
utilize a specific consul binary. By default, it will pick the first `consul`
available in the PATH.

Release History

This version
History Node


History Node


Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, Size & Hash SHA256 Hash Help File Type Python Version Upload Date
(7.9 kB) Copy SHA256 Hash SHA256
Wheel py2.py3 Mar 1, 2017
(4.8 kB) Copy SHA256 Hash SHA256
Source None Mar 1, 2017

Supported By

Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Kabu Creative Kabu Creative UX & Design Google Google Cloud Servers Fastly Fastly CDN StatusPage StatusPage Statuspage DigiCert DigiCert EV Certificate