|
25 | 25 | from qiskit_experiments.framework.json import ExperimentEncoder, ExperimentDecoder
|
26 | 26 |
|
27 | 27 |
|
28 |
| -class TestLibrary(FixedFrequencyTransmon): |
| 28 | +class MutableTestLibrary(FixedFrequencyTransmon): |
29 | 29 | """A subclass designed for test_hash_warn.
|
30 | 30 |
|
31 | 31 | This class ensures that FixedFrequencyTransmon is preserved if anything goes wrong
|
@@ -197,26 +197,27 @@ def test_hash_warn(self):
|
197 | 197 | 4. A warning is raised since the class definition has changed.
|
198 | 198 | """
|
199 | 199 |
|
200 |
| - lib1 = TestLibrary() |
| 200 | + lib1 = MutableTestLibrary() |
201 | 201 | lib_data = json.dumps(lib1, cls=ExperimentEncoder)
|
202 | 202 | lib2 = json.loads(lib_data, cls=ExperimentDecoder)
|
203 | 203 |
|
204 | 204 | self.assertTrue(self._test_library_equivalence(lib1, lib2))
|
205 | 205 |
|
206 | 206 | # stash method build schedules to avoid other tests from failing
|
207 |
| - build_schedules = TestLibrary._build_schedules |
| 207 | + build_schedules = MutableTestLibrary._build_schedules |
208 | 208 |
|
209 | 209 | def _my_build_schedules():
|
210 | 210 | """A dummy function to change the class behaviour."""
|
211 | 211 | pass
|
212 | 212 |
|
213 | 213 | # Change the schedule behaviour
|
214 |
| - TestLibrary._build_schedules = _my_build_schedules |
| 214 | + MutableTestLibrary._build_schedules = _my_build_schedules |
215 | 215 |
|
216 | 216 | with self.assertWarns(UserWarning):
|
217 |
| - json.loads(lib_data, cls=ExperimentDecoder) |
218 |
| - |
219 |
| - TestLibrary._build_schedules = build_schedules |
| 217 | + try: |
| 218 | + json.loads(lib_data, cls=ExperimentDecoder) |
| 219 | + finally: |
| 220 | + MutableTestLibrary._build_schedules = build_schedules |
220 | 221 |
|
221 | 222 | def _test_library_equivalence(self, lib1, lib2) -> bool:
|
222 | 223 | """Test if libraries are equivalent.
|
|
0 commit comments