diff --git a/.stestr.conf b/.stestr.conf index f21840bb584b..cd26f5dfae1a 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 a21f70942cf9..d37bc52d0d5c 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 @@ 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 be687a18c16d..c13e1c05e4dc 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 @@ def test_plot_gate_map(self, backend): """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 @@ def test_plot_circuit_layout(self, backend): 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.")