No description, website, or topics provided.
Switch branches/tags
Nothing to show
Clone or download
Jonathan Moss
Latest commit b503114 Jun 28, 2017

README.rst

A Simple Python Example of Using Pact Testing

The project provides a simple example of Pact testing with Python from both a consumer and provider perspective using the python-pact package

Installation

First ensure you are inside your virtual environment. Then install the dependencies with pip:

pip install -r requirements.txt

Running the Pact Tests

The example uses pyinvoke as a task runner (the tasks themselves can be seen in tasks.py). You will first need to run the consumer tests. These create the pact files we will later be verifying with pact.

invoke test_consumer

In addition to a bunch of temporary folders/files this will generate a pact JSON file called consumer-provider.json on successfully running the tests. This is the pact file we will be validating against a real instance of the service.

Once that is completed, we can validate the pact file with:

invoke test_provider

To make things a little easy to run, the test_provider invoke task automatically starts an testing instance of the provider in a separate thread and closes it again after the validate has been completed. In a real world situation that would likely be handled by the CI server or at least another process.

To Do

This example shows the creation of pact files on the consumer side, as well as verifying those pact files on the provider side. Currently missing is an example of provider states. In our example we use the BDD approach of describing a test in the given, upon, then syntax. Pact testing allows for the writing of state files/code to set up these state during a verification with the --provider-states-url and --provider-states-setup-url switches.