I want to test a nullable field with pact, so I have one test where
def test_post_1(pact, client):
(
pact.given("object doesnt exist")
.upon_receiving("a new post request with data")
.with_request(
"post", "/api/post/new_data",
headers={"Content-Type": "application/json"},
body{"key": Like("some data")},
)
.will_respond_with(200, body={})
)
with pact:
response = client.post_data(
data={"key": "some data"}
)
pact.verify()
And a second test with
def test_post_2(pact, client):
(
pact.given("object doesnt exist")
.upon_receiving("a new post request")
.with_request(
"post", "/api/post/new_data",
headers={"Content-Type": "application/json"},
body{"key": None},
)
.will_respond_with(200, body={})
)
with pact:
response = client.post_data(
data={"key": None}
)
pact.verify()
When I run each test independently they pass. When run together the second test fails with the error that a string was expected but it received null.
Why is the pact state not updating between tests? The pact here is a fixture shared between both tests and defined in a conftest.py file. I've set the fixture scope from "session" to "function" to try and force it to be regenerated, but this doesn't make any difference.
The unique identifiers of a pact test are the description and any provider states. If they don't change between tests, you will get this conflict.
If you could share your test setup that would help us point you in the right direction.