pythonwindows-subsystem-for-linuxpact

Pact file not being saved to configured directory


For some reason the Json contract file Pact generates after running the test I created is being saved to the project's root folder instead of using the path I have defined on its configuration. This application is running in WSL, and it saves to the wrong place in the virtual environment and in my local folder, too.

I have used their example from their documentation and tried writing the path in different ways, but nothing seems to work.

I'm using pact-python>=2.2.2, and installed it using uv.

This is what I added to my conftest.py file:

@pytest.fixture(scope="module")
def pact() -> Generator[Pact, None, None]:
    consumer = Consumer("Consumer")
    pact_dir = Path(Path(__file__).parent / "contract/pacts")

    pact = consumer.has_pact_with(
        Provider("Provider"),
        pact_dir=pact_dir,
        # publish_to_broker=True,
        # Mock service configuration
        # host_name=MOCK_URL.host,
        # port=MOCK_URL.port,
        # Broker configuration
        # broker_base_url=str(broker),
        # broker_username=broker.user,
        # broker_password=broker.password,
    )
    
    pact.start_service()
    yield pact
    pact.stop_service()

I ran the test in debug mode, checked the pact_dir and it is set as it's supposed to be.

PosixPath('/mnt/c/project/tests/contract/pacts')

I'm starting to suspect it could be an issue with Pact itself, but can't be sure.


Solution

  • A bug was opened a while back addressing this issue. As you can see in the interactions, I ended up using another tool for the test I needed writing, but it seems that what caused the problem with Pact was having set file_write_mode to merge. Seems that for some reason that couldn't be replicated, Pact retained this setting option even after l had removed it from its initialization.