Skip to content

Commit 3d9492f

Browse files
authored
Make sure the closefigures fixture is defined (#5970)
* Add missing import of matplotlib.pyplot `test_calibration_plot_histograms` references matplotlib.pyplot, but that module is not imported by default. * Fix missing definition of the closefigures fixture Problem: closefigures fixture is defined in the global conftest.py, which is not included in cirq packages. Package archives thus contain tests with undefined fixture. Solution: move closefigures definition to package conftest.py files. * Fix function reference
1 parent 7892143 commit 3d9492f

File tree

5 files changed

+41
-9
lines changed

5 files changed

+41
-9
lines changed

cirq-core/cirq/conftest.py

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

1515
import inspect
1616
import os
17+
1718
import matplotlib.pyplot as plt
19+
import pytest
1820

1921

2022
def pytest_configure(config):
@@ -30,3 +32,9 @@ def pytest_pyfunc_call(pyfuncitem):
3032
f'{pyfuncitem._obj.__name__} is a bare async function. '
3133
f'It should be decorated with "@duet.sync".'
3234
)
35+
36+
37+
@pytest.fixture
38+
def closefigures():
39+
yield
40+
plt.close('all')

cirq-google/cirq_google/conftest.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,15 @@
1313
# limitations under the License.
1414

1515
import os
16+
import matplotlib.pyplot as plt
17+
import pytest
1618

1719

1820
def pytest_configure(config):
1921
os.environ['CIRQ_TESTING'] = "true"
22+
23+
24+
@pytest.fixture
25+
def closefigures():
26+
yield
27+
plt.close('all')

cirq-google/cirq_google/engine/calibration_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import pytest
1717

1818
import matplotlib as mpl
19+
import matplotlib.pyplot as plt
1920
from google.protobuf.text_format import Merge
2021

2122
import cirq
@@ -194,7 +195,7 @@ def test_calibration_heatmap():
194195
@pytest.mark.usefixtures('closefigures')
195196
def test_calibration_plot_histograms():
196197
calibration = cg.Calibration(_CALIBRATION_DATA)
197-
_, ax = mpl.pyplot.subplots(1, 1)
198+
_, ax = plt.subplots(1, 1)
198199
calibration.plot_histograms(['t1', 'two_qubit_xeb'], ax, labels=['T1', 'XEB'])
199200
assert len(ax.get_lines()) == 4
200201

conftest.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,3 @@ def pytest_addoption(parser):
3737
default=False,
3838
help="run Rigetti integration tests",
3939
)
40-
41-
42-
@pytest.fixture
43-
def closefigures():
44-
import matplotlib.pyplot as plt
45-
46-
yield
47-
plt.close('all')

examples/conftest.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright 2022 The Cirq Developers
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
16+
import matplotlib.pyplot as plt
17+
import pytest
18+
19+
20+
@pytest.fixture
21+
def closefigures():
22+
yield
23+
plt.close('all')

0 commit comments

Comments
 (0)