Skip to content

Commit 5e7bc33

Browse files
authored
Add missing import of qiskit.qasm2 in unit test (#7137)
* Add missing import of qiskit.qasm2 in unit test The `qiskit.qasm2` submodule needs to be imported explicitly. Also simplify test-skipping when qiskit is not installed. Fixes failure of the CI `Coverage check` job. * Address typecheck
1 parent ed7ea48 commit 5e7bc33

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

cirq-core/cirq/contrib/qasm_import/_parser_test.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
import re
1616
import textwrap
17-
import warnings
1817
from typing import Callable
1918

2019
import numpy as np
@@ -1486,19 +1485,14 @@ def _test_parse_exception(qasm: str, cirq_err: str, qiskit_err: str | None):
14861485
parser = QasmParser()
14871486
with pytest.raises(QasmException, match=re.escape(cirq_err)):
14881487
parser.parse(qasm)
1489-
try:
1490-
import qiskit
1491-
1492-
if qiskit_err is None:
1493-
qiskit.QuantumCircuit.from_qasm_str(qasm)
1494-
return
1495-
with pytest.raises(qiskit.qasm2.exceptions.QASM2ParseError, match=re.escape(qiskit_err)):
1496-
qiskit.QuantumCircuit.from_qasm_str(qasm)
1497-
except ImportError: # pragma: no cover
1498-
warnings.warn(
1499-
"Skipped _test_qiskit_parse_exception because "
1500-
"qiskit isn't installed to verify against."
1501-
)
1488+
pytest.importorskip("qiskit")
1489+
import qiskit.qasm2
1490+
1491+
if qiskit_err is None:
1492+
qiskit.QuantumCircuit.from_qasm_str(qasm)
1493+
return
1494+
with pytest.raises(qiskit.qasm2.exceptions.QASM2ParseError, match=re.escape(qiskit_err)):
1495+
qiskit.QuantumCircuit.from_qasm_str(qasm)
15021496

15031497

15041498
def test_nested_custom_gate_has_keyword_in_name():

0 commit comments

Comments
 (0)