import pytest from pact import Consumer, Provider import requests # Example PACT test for a service-to-service contract def test_pact_with_inventory_provider(): # Arrange pact = Consumer('ShopService').has_pact_with(Provider('InventoryProvider'), port=1234) expected = { 'id': 1, 'name': 'Sword', 'quantity': 10 } (pact .given('Inventory item exists') .upon_receiving('a request for inventory item') .with_request('get', '/inventory/1') .will_respond_with(200, body=expected)) with pact: # Act result = requests.get('http://localhost:1234/inventory/1') # Assert assert result.json() == expected