forked from PennyLaneAI/catalyst
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
53 lines (40 loc) · 1.41 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
"""Setup pytest configurations."""
import pytest
def pytest_addoption(parser):
"""Add pytest custom options."""
parser.addoption(
"--backend",
action="store",
default="lightning.qubit",
help="Name of the backend device",
)
parser.addoption(
"--runbraket",
action="store",
default="OFF",
help="Run AWS Braket tests; runtime must be compiled with `ENABLE_OPENQASM=ON`",
)
def pytest_generate_tests(metafunc):
"""A pytest fixture to define custom parametrization"""
if "backend" in metafunc.fixturenames:
metafunc.parametrize("backend", [metafunc.config.getoption("--backend")])
def pytest_configure(config):
"""A pytest configure helper method"""
config.addinivalue_line(
"markers", "braket: run on aws-braket devices using `OpenQasmDevice` in the runtime"
)
def pytest_collection_modifyitems(config, items):
"""A pytest items modifier method"""
if config.getoption("--runbraket") == "ON":
# only runs test with the braket marker
braket_tests = []
for item in items:
if item.get_closest_marker("braket"):
braket_tests.append(item)
items[:] = braket_tests
else:
# skip braket tests
skipper = pytest.mark.skip()
for item in items:
if "braket" in item.keywords:
item.add_marker(skipper)