Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How-To: Verify multiple pacts in a directory or from multiple file path locations #362

Closed
YOU54F opened this issue Jul 25, 2023 · 0 comments

Comments

@YOU54F
Copy link
Member

YOU54F commented Jul 25, 2023

We got asked the question in slack, as to whether you could verify pacts in a directory or from multiple locations.

The function currently expects a comma separated string of file paths, so passing a directory as the first argument will fail.

Here are a couple of examples. feel free to add your own

Read by Directory

This commit shows a working example (utilising pact-python 2.0.0)

88918cf

    def list_full_paths(directory):
        return [os.path.join(directory, file) for file in os.listdir(directory)]

    output, _ = verifier.verify_pacts(
        ','.join(map(str, list_full_paths("../pacts"))),
        verbose=False,
        provider_states_setup_url="{}/_pact/provider_states".format(PROVIDER_URL),
    )

Might not be an ideal solution, but if it gets readers out of a bind.

Read from multiple locations

Solution provided by Ivan Mikhalka over in Slack, thanks 👍🏾

            pact_files = []
            if not os.environ.get("CONSUMER_1_CONTRACT_PATH") is None:
                pact_files.append("{}".format(os.environ["CONSUMER_1_CONTRACT_PATH"]))
            if not os.environ.get("CONSUMER_2_CONTRACT_PATH") is None:
                pact_files.append("{}".format(os.environ["CONSUMER_2_CONTRACT_PATH"]))
            success, logs = verifier.verify_pacts(*pact_files)
export CONSUMER_1_CONTRACT=<path/to/contract1> && export CONSUMER_2_CONTRACT=<path/to/contract2> && pytest provider_test.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant