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

Enforce CFSSL/RHSSO/Mockserver skips #341

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions testsuite/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ def pytest_runtest_setup(item):
marks = [i.name for i in item.iter_markers()]
if "performance" in marks and not item.config.getoption("--performance"):
pytest.skip("Excluding performance tests")
skip_func = pytest.fail if item.config.getoption("--enforce") else pytest.skip
skip_or_fail = pytest.fail if item.config.getoption("--enforce") else pytest.skip
if "kuadrant_only" in marks:
kuadrant, error = has_kuadrant()
if not kuadrant:
skip_func(f"Unable to locate Kuadrant installation: {error}")
skip_or_fail(f"Unable to locate Kuadrant installation: {error}")
if "standalone_only" in marks:
status, error = is_standalone()
if not status:
skip_func(f"Unable to run Standalone tests: {error}")
skip_or_fail(f"Unable to run Standalone tests: {error}")
if "mgc" in marks:
mgc, error = has_mgc()
if not mgc:
skip_func(f"Unable to locate MGC installation: {error}")
skip_or_fail(f"Unable to locate MGC installation: {error}")


@pytest.hookimpl(hookwrapper=True)
Expand All @@ -76,6 +76,12 @@ def pytest_runtest_makereport(item, call): # pylint: disable=unused-argument
report.extra = extra


@pytest.fixture(scope="session")
def skip_or_fail(request):
"""Skips or fails tests depending on --enforce option"""
return pytest.fail if request.config.getoption("--enforce") else pytest.skip


@pytest.fixture(scope="session", autouse=True)
def term_handler():
"""
Expand Down Expand Up @@ -121,18 +127,18 @@ def openshift(testconfig):


@pytest.fixture(scope="module")
def openshift2(testconfig):
def openshift2(testconfig, skip_or_fail):
"""OpenShift client for the secondary namespace located on the same cluster as primary Openshift"""
client = testconfig["service_protection"]["project2"]
if client is None:
pytest.skip("Openshift2 required but second_project was not set")
skip_or_fail("Openshift2 required but second_project was not set")
if not client.connected:
pytest.fail("You are not logged into Openshift or the namespace for Openshift2 doesn't exist")
return client


@pytest.fixture(scope="session")
def rhsso(request, testconfig, blame):
def rhsso(request, testconfig, blame, skip_or_fail):
"""RHSSO OIDC Provider fixture"""
try:
testconfig.validators.validate(only="rhsso")
Expand All @@ -153,9 +159,9 @@ def rhsso(request, testconfig, blame):
info.commit()
return info
except KeycloakAuthenticationError:
return pytest.skip("Unable to login into SSO, please check the credentials provided")
return skip_or_fail("Unable to login into SSO, please check the credentials provided")
except KeyError as exc:
return pytest.skip(f"SSO configuration item is missing: {exc}")
return skip_or_fail(f"SSO configuration item is missing: {exc}")


@pytest.fixture(scope="session")
Expand All @@ -169,22 +175,22 @@ def auth0(testconfig):


@pytest.fixture(scope="session")
def cfssl(testconfig):
def cfssl(testconfig, skip_or_fail):
"""CFSSL client library"""
client = CFSSLClient(binary=testconfig["cfssl"])
if not client.exists:
pytest.skip("Skipping CFSSL tests as CFSSL binary path is not properly configured")
skip_or_fail("Skipping CFSSL tests as CFSSL binary path is not properly configured")
return client


@pytest.fixture(scope="module")
def mockserver(testconfig):
def mockserver(testconfig, skip_or_fail):
"""Returns mockserver"""
try:
testconfig.validators.validate(only=["mockserver"])
return Mockserver(testconfig["mockserver"]["url"])
except (KeyError, ValidationError) as exc:
return pytest.skip(f"Mockserver configuration item is missing: {exc}")
return skip_or_fail(f"Mockserver configuration item is missing: {exc}")


@pytest.fixture(scope="session")
Expand Down
Loading