Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(examples): move shared fixtures to a common folder so they can b…
…e reused, remove repeated code
- Loading branch information
1 parent
c568afe
commit 50fc4a2
Showing
1 changed file
with
6 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,8 @@ | ||
import pytest | ||
from testcontainers.compose import DockerCompose | ||
import sys | ||
|
||
# Load in the fixtures from common/sharedfixtures.py | ||
sys.path.append("../common") | ||
|
||
def pytest_addoption(parser): | ||
parser.addoption( | ||
"--publish-pact", | ||
type=str, | ||
action="store", | ||
help="Upload generated Pact file to Pact Broker with the version provided", | ||
) | ||
|
||
parser.addoption("--run-broker", type=bool, action="store", help="Whether to run broker in this test or not") | ||
|
||
|
||
# This fixture is to simulate a managed Pact Broker or Pactflow account. | ||
# For almost all purposes outside this example, you will want to use a real | ||
# broker. See https://github.com/pact-foundation/pact_broker for further details. | ||
@pytest.fixture(scope="session", autouse=True) | ||
def broker(request): | ||
version = request.config.getoption("--publish-pact") | ||
publish = True if version else False | ||
|
||
# If the results are not going to be published to the broker, there is | ||
# nothing further to do anyway | ||
if not publish: | ||
yield | ||
return | ||
|
||
run_broker = request.config.getoption("--run-broker") | ||
|
||
if run_broker: | ||
# Start up the broker using docker-compose | ||
print("Starting broker") | ||
with DockerCompose("../broker", compose_file_name=["docker-compose.yml"], pull=True) as compose: | ||
stdout, stderr = compose.get_logs() | ||
if stderr: | ||
print("Errors\\n:{}".format(stderr)) | ||
print("{}".format(stdout)) | ||
print("Started broker") | ||
|
||
yield | ||
print("Stopping broker") | ||
print("Broker stopped") | ||
else: | ||
# Assuming there is a broker available already, docker-compose has been | ||
# used manually as the --run-broker option has not been provided | ||
yield | ||
return | ||
pytest_plugins = [ | ||
"sharedfixtures", | ||
] |