Skip to content

Moved rigetti integration test logic to higher level conftest.py file… #6328

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

Merged
merged 10 commits into from
Oct 27, 2023
Merged
21 changes: 0 additions & 21 deletions cirq-rigetti/cirq_rigetti/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,6 @@
import sympy
import numpy as np


def pytest_collection_modifyitems(config, items): # pragma: no cover
# do not skip integration tests if --rigetti-integration option passed
if config.getoption('--rigetti-integration'):
return
# do not skip integration tests rigetti_integration marker explicitly passed.
if 'rigetti_integration' in config.getoption('-m'):
return
# otherwise skip all tests marked "rigetti_integration".
skip_rigetti_integration = pytest.mark.skip(reason="need --rigetti-integration option to run")
for item in items:
if "rigetti_integration" in item.keywords:
item.add_marker(skip_rigetti_integration)


def pytest_configure(config):
config.addinivalue_line(
"markers", "rigetti_integration: tests that connect to Quil compiler or QVM."
)


T = TypeVar("T")


Expand Down
29 changes: 29 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,32 @@ def pytest_addoption(parser):
default=False,
help="run Rigetti integration tests",
)
parser.addoption(
"--enable-slow-tests", action="store_true", default=False, help="run slow tests"
)


def pytest_collection_modifyitems(config, items):
# Let pytest handle markexpr if present. Make an exception for
# `pytest --co -m skip` so we can check test skipping rules below.
markexpr_words = frozenset(config.option.markexpr.split())
if not markexpr_words.issubset(["not", "skip"]):
return # pragma: no cover

# our marks for tests to be skipped by default
skip_marks = {
"rigetti_integration": pytest.mark.skip(reason="need --rigetti-integration option to run"),
"slow": pytest.mark.skip(reason="need --enable-slow-tests option to run"),
"weekly": pytest.mark.skip(reason='only run by weekly automation'),
}

# drop skip_marks for tests enabled by command line options
if config.option.rigetti_integration:
del skip_marks["rigetti_integration"] # pragma: no cover
if config.option.enable_slow_tests:
del skip_marks["slow"] # pragma: no cover
skip_keywords = frozenset(skip_marks.keys())

for item in items:
for k in skip_keywords.intersection(item.keywords):
item.add_marker(skip_marks[k])
21 changes: 0 additions & 21 deletions dev_tools/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,6 @@
from dev_tools.env_tools import create_virtual_env


def pytest_configure(config):
config.addinivalue_line("markers", "slow: mark tests as slow")
config.addinivalue_line("markers", "weekly: mark tests as run only by weekly automation")


def pytest_collection_modifyitems(config, items):
markexpr = config.option.markexpr
if markexpr:
return # let pytest handle this

skip_slow_marker = pytest.mark.skip(reason='slow marker not selected')
for item in items:
if 'slow' in item.keywords:
item.add_marker(skip_slow_marker)

skip_weekly_marker = pytest.mark.skip(reason='only run by weekly automation')
for item in items:
if 'weekly' in item.keywords:
item.add_marker(skip_weekly_marker)


@pytest.fixture(scope="session")
def cloned_env(testrun_uid, worker_id):
"""Fixture to allow tests to run in a clean virtual env.
Expand Down
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@ skip-magic-trailing-comma = true
filterwarnings = [
"ignore:Matplotlib is currently using agg:UserWarning",
]
markers = [
"rigetti_integration: tests that connect to Quil compiler or QVM.",
"slow: slow tests that should be skipped by default.",
"weekly: tests to be run only by weekly CI automation.",
]