Conftest¶
Shared PyTest configuration.
In order to run the examples, we need to run the Pact broker. In order to avoid having to run the Pact broker manually, or repeating the same code in each example, we define a PyTest fixture to run the Pact broker.
We also define a pact_dir
fixture to define the directory where the generated
Pact files will be stored. You are encouraged to have a look at these files
after the examples have been run.
Attributes¶
EXAMPLE_DIR = Path(__file__).parent.resolve()
module-attribute
¶
Functions¶
broker(request: pytest.FixtureRequest) -> Generator[URL, Any, None]
¶
Fixture to run the Pact broker.
This inspects whether the --broker-url
option has been given. If it has,
it is assumed that the broker is already running and simply returns the
given URL.
Otherwise, the Pact broker is started in a container. The URL of the containerised broker is then returned.
Source code in examples/conftest.py
pact_dir() -> Path
¶
pytest_xdist_setupnodes(config: pytest.Config, specs: Sequence[execnet.XSpec]) -> None
¶
Hook to check if the examples are run with multiple workers.
The examples are designed to run in a specific order, with the consumer tests running before the provider tests as the provider tests require that the consumer-generated Pacts are published.
If multiple xdist workers are detected, a warning is printed to the console.