Skip to content

Commit

Permalink
test(examples): move shared fixtures to a common folder so they can b…
Browse files Browse the repository at this point in the history
…e reused, remove repeated code
  • Loading branch information
mikegeeves committed Feb 10, 2022
1 parent c568afe commit 50fc4a2
Showing 1 changed file with 6 additions and 47 deletions.
53 changes: 6 additions & 47 deletions examples/consumer/conftest.py
@@ -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",
]

0 comments on commit 50fc4a2

Please sign in to comment.