admin管理员组

文章数量:1123430

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.

本文标签: pythonPact file not being saved to configured directoryStack Overflow