From 5664ab44396b579c8fc4dddfce1b8d73457af2e8 Mon Sep 17 00:00:00 2001 From: jorconnor Date: Wed, 12 May 2021 15:06:06 -0400 Subject: [PATCH] Removes stestr's grouping configuration. (#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 #6105 --- .stestr.conf | 1 - test/python/test_user_config.py | 7 ++++--- test/python/visualization/test_gate_map.py | 21 ++++++++++++--------- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/.stestr.conf b/.stestr.conf index f21840bb58..cd26f5dfae 100644 --- a/.stestr.conf +++ b/.stestr.conf @@ -1,3 +1,2 @@ [DEFAULT] test_path=./test/python -group_regex=([^\.]*\.)* diff --git a/test/python/test_user_config.py b/test/python/test_user_config.py index a21f70942c..d37bc52d0d 100644 --- a/test/python/test_user_config.py +++ b/test/python/test_user_config.py @@ -13,6 +13,7 @@ # pylint: disable=missing-docstring import os +from uuid import uuid4 from qiskit import exceptions from qiskit.test import QiskitTestCase @@ -20,9 +21,9 @@ from qiskit import user_config class TestUserConfig(QiskitTestCase): - @classmethod - def setUpClass(cls): - cls.file_path = "temp.txt" + def setUp(self): + super().setUp() + self.file_path = "test_%s.conf" % uuid4() def test_empty_file_read(self): config = user_config.UserConfig(self.file_path) diff --git a/test/python/visualization/test_gate_map.py b/test/python/visualization/test_gate_map.py index be687a18c1..c13e1c05e4 100644 --- a/test/python/visualization/test_gate_map.py +++ b/test/python/visualization/test_gate_map.py @@ -12,8 +12,9 @@ """A test for visualizing device coupling maps""" import unittest -import os +from io import BytesIO +from PIL import Image from ddt import ddt, data from qiskit.test.mock import FakeProvider from qiskit.test import QiskitTestCase @@ -45,11 +46,12 @@ class TestGateMap(QiskitVisualizationTestCase): """tests plotting of gate map of a device (20 qubit, 16 qubit, 14 qubit and 5 qubit)""" n = backend.configuration().n_qubits img_ref = path_to_diagram_reference(str(n) + "bit_quantum_computer.png") - filename = "temp.png" fig = plot_gate_map(backend) - fig.savefig(filename) - self.assertImagesAreEqual(filename, img_ref, 0.2) - os.remove(filename) + with BytesIO() as img_buffer: + fig.savefig(img_buffer, format="png") + img_buffer.seek(0) + self.assertImagesAreEqual(Image.open(img_buffer), img_ref, 0.2) + plt.close(fig) @data(*backends) @unittest.skipIf(not HAS_MATPLOTLIB, "matplotlib not available.") @@ -62,11 +64,12 @@ class TestGateMap(QiskitVisualizationTestCase): circuit._layout.add_register(qr) n = backend.configuration().n_qubits img_ref = path_to_diagram_reference(str(n) + "_plot_circuit_layout.png") - filename = str(n) + "_plot_circuit_layout_result.png" fig = plot_circuit_layout(circuit, backend) - fig.savefig(filename) - self.assertImagesAreEqual(filename, img_ref, 0.1) - os.remove(filename) + with BytesIO() as img_buffer: + fig.savefig(img_buffer, format="png") + img_buffer.seek(0) + self.assertImagesAreEqual(Image.open(img_buffer), img_ref, 0.1) + plt.close(fig) @unittest.skipIf(not HAS_MATPLOTLIB, "matplotlib not available.")