Skip to content

Commit 5664ab4

Browse files
authored
Removes stestr's grouping configuration. (Qiskit#6399)
Removing the grouping regex in .stestr.conf should allow stestr to pack its test workers better, and therefore improve the speed of test execution. However, pre-existing test cases utilizing non-unique tempfiles began to fail after the configuration change. This commit modifies such tests to pass under these new conditions. This also allows the test suite to properly execute using pytest-xdist. Fixed Qiskit#6105
1 parent 9b78934 commit 5664ab4

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

.stestr.conf

-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
[DEFAULT]
22
test_path=./test/python
3-
group_regex=([^\.]*\.)*

test/python/test_user_config.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,17 @@
1313
# pylint: disable=missing-docstring
1414

1515
import os
16+
from uuid import uuid4
1617

1718
from qiskit import exceptions
1819
from qiskit.test import QiskitTestCase
1920
from qiskit import user_config
2021

2122

2223
class TestUserConfig(QiskitTestCase):
23-
@classmethod
24-
def setUpClass(cls):
25-
cls.file_path = "temp.txt"
24+
def setUp(self):
25+
super().setUp()
26+
self.file_path = "test_%s.conf" % uuid4()
2627

2728
def test_empty_file_read(self):
2829
config = user_config.UserConfig(self.file_path)

test/python/visualization/test_gate_map.py

+12-9
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212

1313
"""A test for visualizing device coupling maps"""
1414
import unittest
15-
import os
1615

16+
from io import BytesIO
17+
from PIL import Image
1718
from ddt import ddt, data
1819
from qiskit.test.mock import FakeProvider
1920
from qiskit.test import QiskitTestCase
@@ -45,11 +46,12 @@ def test_plot_gate_map(self, backend):
4546
"""tests plotting of gate map of a device (20 qubit, 16 qubit, 14 qubit and 5 qubit)"""
4647
n = backend.configuration().n_qubits
4748
img_ref = path_to_diagram_reference(str(n) + "bit_quantum_computer.png")
48-
filename = "temp.png"
4949
fig = plot_gate_map(backend)
50-
fig.savefig(filename)
51-
self.assertImagesAreEqual(filename, img_ref, 0.2)
52-
os.remove(filename)
50+
with BytesIO() as img_buffer:
51+
fig.savefig(img_buffer, format="png")
52+
img_buffer.seek(0)
53+
self.assertImagesAreEqual(Image.open(img_buffer), img_ref, 0.2)
54+
plt.close(fig)
5355

5456
@data(*backends)
5557
@unittest.skipIf(not HAS_MATPLOTLIB, "matplotlib not available.")
@@ -62,11 +64,12 @@ def test_plot_circuit_layout(self, backend):
6264
circuit._layout.add_register(qr)
6365
n = backend.configuration().n_qubits
6466
img_ref = path_to_diagram_reference(str(n) + "_plot_circuit_layout.png")
65-
filename = str(n) + "_plot_circuit_layout_result.png"
6667
fig = plot_circuit_layout(circuit, backend)
67-
fig.savefig(filename)
68-
self.assertImagesAreEqual(filename, img_ref, 0.1)
69-
os.remove(filename)
68+
with BytesIO() as img_buffer:
69+
fig.savefig(img_buffer, format="png")
70+
img_buffer.seek(0)
71+
self.assertImagesAreEqual(Image.open(img_buffer), img_ref, 0.1)
72+
plt.close(fig)
7073

7174

7275
@unittest.skipIf(not HAS_MATPLOTLIB, "matplotlib not available.")

0 commit comments

Comments
 (0)