diff --git a/test/calibration/test_setup_library.py b/test/calibration/test_setup_library.py index 1c1307c97a..12900dbf38 100644 --- a/test/calibration/test_setup_library.py +++ b/test/calibration/test_setup_library.py @@ -25,7 +25,7 @@ from qiskit_experiments.framework.json import ExperimentEncoder, ExperimentDecoder -class TestLibrary(FixedFrequencyTransmon): +class MutableTestLibrary(FixedFrequencyTransmon): """A subclass designed for test_hash_warn. This class ensures that FixedFrequencyTransmon is preserved if anything goes wrong @@ -197,26 +197,27 @@ def test_hash_warn(self): 4. A warning is raised since the class definition has changed. """ - lib1 = TestLibrary() + lib1 = MutableTestLibrary() lib_data = json.dumps(lib1, cls=ExperimentEncoder) lib2 = json.loads(lib_data, cls=ExperimentDecoder) self.assertTrue(self._test_library_equivalence(lib1, lib2)) # stash method build schedules to avoid other tests from failing - build_schedules = TestLibrary._build_schedules + build_schedules = MutableTestLibrary._build_schedules def _my_build_schedules(): """A dummy function to change the class behaviour.""" pass # Change the schedule behaviour - TestLibrary._build_schedules = _my_build_schedules + MutableTestLibrary._build_schedules = _my_build_schedules with self.assertWarns(UserWarning): - json.loads(lib_data, cls=ExperimentDecoder) - - TestLibrary._build_schedules = build_schedules + try: + json.loads(lib_data, cls=ExperimentDecoder) + finally: + MutableTestLibrary._build_schedules = build_schedules def _test_library_equivalence(self, lib1, lib2) -> bool: """Test if libraries are equivalent.