diff --git a/test/ibm_test_case.py b/test/ibm_test_case.py index 2878597d4..ac91782a6 100644 --- a/test/ibm_test_case.py +++ b/test/ibm_test_case.py @@ -17,6 +17,7 @@ import logging import inspect import unittest +import warnings from contextlib import suppress from collections import defaultdict from typing import DefaultDict, Dict @@ -45,6 +46,8 @@ def setUpClass(cls): filename = "%s.log" % os.path.splitext(inspect.getfile(cls))[0] setup_test_logging(cls.log, filename) cls._set_logging_level(logging.getLogger(QISKIT_IBM_RUNTIME_LOGGER_NAME)) + # fail test on deprecation warnings from qiskit + warnings.filterwarnings("error", category=DeprecationWarning, module="qiskit") @classmethod def _set_logging_level(cls, logger: logging.Logger) -> None: diff --git a/test/unit/test_data_serialization.py b/test/unit/test_data_serialization.py index 604b78cb1..91e6ea8da 100644 --- a/test/unit/test_data_serialization.py +++ b/test/unit/test_data_serialization.py @@ -96,15 +96,10 @@ def test_coder_operators(self): # filter warnings triggered by opflow imports with warnings.catch_warnings(): - warnings.filterwarnings( - "ignore", category=DeprecationWarning, module=r"qiskit\.opflow\." - ) + warnings.filterwarnings("ignore", category=DeprecationWarning) from qiskit.opflow import PauliSumOp # pylint: disable=import-outside-toplevel - # catch warnings triggered by opflow use - with warnings.catch_warnings(record=True) as w_log: deprecated_op = PauliSumOp(SparsePauliOp(Pauli("XYZX"), coeffs=[2])) - self.assertTrue(len(w_log) > 0) coeff_x = Parameter("x") coeff_y = coeff_x + 1 @@ -124,14 +119,7 @@ def test_coder_operators(self): with warnings.catch_warnings(): # filter warnings triggered by opflow imports # in L146 of utils/json.py - warnings.filterwarnings( - "ignore", category=DeprecationWarning, module=r"qiskit\.opflow\." - ) - warnings.filterwarnings( - "ignore", - category=DeprecationWarning, - module=r"qiskit_ibm_runtime\.utils\.json", - ) + warnings.filterwarnings("ignore", category=DeprecationWarning) decoded = json.loads(encoded, cls=RuntimeDecoder) self.assertEqual(operator, decoded) @@ -141,7 +129,12 @@ def test_coder_noise_model(self): self.assertIsInstance(noise_model, NoiseModel) encoded = json.dumps(noise_model, cls=RuntimeEncoder) self.assertIsInstance(encoded, str) - decoded = json.loads(encoded, cls=RuntimeDecoder) + with warnings.catch_warnings(): + warnings.filterwarnings( + "ignore", + category=DeprecationWarning, + ) + decoded = json.loads(encoded, cls=RuntimeDecoder) self.assertIsInstance(decoded, NoiseModel) self.assertEqual(noise_model.noise_qubits, decoded.noise_qubits) self.assertEqual(noise_model.noise_instructions, decoded.noise_instructions)