Skip to main content

Pact Test Generator

https://img.shields.io/pypi/v/pact-testgen.svg https://img.shields.io/travis/pymetrics/pact-testgen.svg Documentation Status

Generate Python test cases from Pact files, for easier provider verification.

Features

  • Test Pact contracts against your Python providers via unit tests. Get test isolation for free.

  • pact-testgen creates test cases from your Pact files, with placeholders for defining provider states.

Getting Started

Install with pip

python -m pip install pact-testgen

Generate test files

Generate a provider_states.py and test_pact.py files in your tests directory:

pact-testgen /tests/dir -f /path/to/pactfile.json

For more details, see the Usage section of the documentation.

Fill in the generated provider states file

In your tests directory (passed as the first argument to pact-testgen), you’ll see a file named provider_states.py. It will contain set up functions matching the provider states defined in your pact file.

Before continuing, complete these functions so that they create the required states.

Run your tests

Run your test suite as normal, being sure to check the the test runner has picked up your new test_pact.py file.

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

Logo Admiranda Urbis Venetæ from the British Library’s King’s Topographical Collection.

Verification of test responses in generated test code is powered by pactman.

History

0.6.0 (2022-10-30)

  • Test against Python 3.10, 3.11

0.5.0 (2022-02-04)

  • Adds Pact Broker support.

0.4.3 (2021-09-20)

  • Fix file handling for merge provider state file option.

0.4.2 (2021-09-18)

  • Improve handling of request data.

0.4.1 (2021-09-17)

  • Fix test method name missing test_.

0.4.0 (2021-09-16)

  • Adds option to merge changes to provider state file (Python 3.9 only).

  • Include structured provider state parameters from Pact v3 in provider state function names.

  • Support null provider state, i.e. pact.given(None).

0.3.0 (2021-09-03)

  • Provider state setup functions now raise NotImplementedError by default.

  • Format output files with target line length option.

  • Improve output to console, add quiet option.

0.2.1 (2021-09-01)

  • Fix test client not setting content type.

0.2.0 (2021-09-01)

  • Improve output for failed test cases.

0.1.2 (2021-08-25)

  • Fix bump2version config

0.1.1 (2021-08-24)

  • Fix templates missing from distributed package.

0.1.0 (2021-08-23)

  • First release on PyPI.

Metadata

Release files for pact-testgen 0.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pact-testgen 0.7.0
File Size Uploaded
pact_testgen-0.7.0.tar.gz 113.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pact-testgen 0.7.0
File Interpreter ABI Platform
pact_testgen-0.7.0-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 130.8 kB

Release files / pact_testgen-0.7.0.tar.gz

Download URL pact_testgen-0.7.0.tar.gz
Size 113.1 kB
Tags Source
SHA-256 checksum
How to use checksums
86631e1036440d703095eeb522d5a13e70a74b3afd0770cc05b3bfcecbe9e484
BLAKE2b-256 checksum
How to use checksums
8ae3c0c2dbbab009d10384141a217e0bb107f6f13ba05ae2824956287f0c95f1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.13

Release files / pact_testgen-0.7.0-py2.py3-none-any.whl

Download URL pact_testgen-0.7.0-py2.py3-none-any.whl
Size 17.7 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
6d02627de42715ad2f976777fe7d17512ef204953da3bd4da1bda19ef52759ad
BLAKE2b-256 checksum
How to use checksums
07609c7d5fa9d1782cbdf7322b60767d3245577f98fee0cb592d0b92a8999b79
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.13

Release history Release notifications | RSS feed

This release

0.7.0 This release

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page