-
Notifications
You must be signed in to change notification settings - Fork 141
/
Copy pathconftest.py
70 lines (55 loc) · 1.98 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"""
Pytest configuration.
As the compatibility suite makes use of a submodule, we need to make sure the
submodule has been initialized before running the tests.
"""
import shutil
import subprocess
from pathlib import Path
from typing import Any, Generator, Union
import pytest
from testcontainers.compose import DockerCompose # type: ignore[import-untyped]
from yarl import URL
from pact.v3.verifier import Verifier
@pytest.fixture(scope="session", autouse=True)
def _submodule_init() -> None:
"""Initialize the submodule."""
# Locate the git execute
submodule_dir = Path(__file__).parent / "definition"
if submodule_dir.is_dir():
return
git_exec = shutil.which("git")
if git_exec is None:
msg = (
"Submodule not initialized and git executable not found."
" Please initialize the submodule with `git submodule init`."
)
raise RuntimeError(msg)
subprocess.check_call([git_exec, "submodule", "init"]) # noqa: S603
@pytest.fixture()
def verifier() -> Verifier:
"""Return a new Verifier."""
return Verifier()
@pytest.fixture(scope="session")
def broker_url(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.
"""
broker_url: Union[str, None] = request.config.getoption("--broker-url")
# If we have been given a broker URL, there's nothing more to do here and we
# can return early.
if broker_url:
yield URL(broker_url)
return
with DockerCompose(
Path(__file__).parent / "util",
compose_file_name="pact-broker.yml",
pull=True,
) as _:
yield URL("http://pactbroker:pactbroker@localhost:9292")
return