tmcfarlane / python-pact-testing-example

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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:

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.

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:

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.

About


Languages

Language:Python 100.0%