Repository navigation
Expand file tree
/
Copy pathconftest.py
More file actions
65 lines (51 loc) · 2.07 KB
/
Copy pathconftest.py
File metadata and controls
65 lines (51 loc) · 2.07 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
"""Collection policy for the optional IBM / Qiskit hardware lane.
These tests import qiskit (and, on some hosts, POSIX-only modules such as
``fcntl``) at import time. The lane is an optional hardware surface, not part of
the mandatory clean-clone scientific suite. Broad collection ignores it. A
direct invocation without the explicit opt-in or complete extras exits with an
actionable message instead of reporting the ambiguous pytest result "no tests
ran".
Opt in after installing ``requirements-ibm.txt``::
OPH_RUN_IBM=1 python -m pytest code/ibm_quantum_cloud
This mirrors the existing opt-in gate for the legacy arXiv D10 helpers
(``OPH_RUN_LEGACY_D10``) in ``code/particles/conftest.py``.
"""
from __future__ import annotations
import importlib.util
import os
from pathlib import Path
import pytest
LANE_ROOT = Path(__file__).resolve().parent
REQUIRED_MODULES = ("qiskit", "qiskit_aer", "qiskit_ibm_runtime")
def _directly_targets_lane(config: pytest.Config) -> bool:
invocation_dir = Path(config.invocation_params.dir)
for raw_arg in config.invocation_params.args:
if raw_arg.startswith("-"):
continue
candidate = (invocation_dir / raw_arg).resolve()
if candidate == LANE_ROOT or LANE_ROOT in candidate.parents:
return True
return False
def pytest_configure(config: pytest.Config) -> None:
if not _directly_targets_lane(config):
return
if os.environ.get("OPH_RUN_IBM") != "1":
pytest.exit(
"IBM/Qiskit is an optional hardware lane. Set OPH_RUN_IBM=1 "
"after installing code/ibm_quantum_cloud/requirements-ibm.txt.",
returncode=4,
)
missing = [
module
for module in REQUIRED_MODULES
if importlib.util.find_spec(module) is None
]
if missing:
pytest.exit(
"IBM/Qiskit optional extras are missing: "
+ ", ".join(missing)
+ ". Install code/ibm_quantum_cloud/requirements-ibm.txt.",
returncode=4,
)
if os.environ.get("OPH_RUN_IBM") != "1":
collect_ignore_glob = ["*"]