diff --git a/tests/uitests/addhardware.py b/tests/uitests/addhardware.py index 74b271487..202626f31 100644 --- a/tests/uitests/addhardware.py +++ b/tests/uitests/addhardware.py @@ -144,15 +144,12 @@ class AddHardware(uiutils.UITestCase): uiutils.check_in_loop(lambda: not addhw.showing) uiutils.check_in_loop(lambda: details.active) + @tests.utils.run_without_testsuite_hacks def testQemuSearchCheck(self): - os.environ.pop("VIRTINST_TEST_SUITE") - try: - with tempfile.TemporaryDirectory() as tmpdir: - with tempfile.NamedTemporaryFile(dir=tmpdir) as tmpfile: - os.chmod(tmpdir, 0o700) - self._testQemuSearchCheck(tmpfile.name) - finally: - os.environ["VIRTINST_TEST_SUITE"] = "1" + with tempfile.TemporaryDirectory() as tmpdir: + with tempfile.NamedTemporaryFile(dir=tmpdir) as tmpfile: + os.chmod(tmpdir, 0o700) + self._testQemuSearchCheck(tmpfile.name) def testAddDisks(self): """ diff --git a/tests/utils.py b/tests/utils.py index d3bf9dae5..c52f711ed 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -225,3 +225,17 @@ def diff_compare(actual_out, filename=None, expect_out=None): tofile="Generated Output")) if diff: raise AssertionError("Conversion outputs did not match.\n%s" % diff) + + +def run_without_testsuite_hacks(cb): + """ + Decorator for unsetting the test suite env variable + """ + def wrapper_cb(*args, **kwargs): + origval = os.environ.pop("VIRTINST_TEST_SUITE", None) + try: + return cb(*args, **kwargs) + finally: + if origval: + os.environ["VIRTINST_TEST_SUITE"] = origval + return wrapper_cb diff --git a/tests/xmlconfig.py b/tests/xmlconfig.py index e4984be51..dab83a586 100644 --- a/tests/xmlconfig.py +++ b/tests/xmlconfig.py @@ -193,28 +193,24 @@ class TestXMLMisc(unittest.TestCase): g._metadata.libosinfo.os_id = "http://example.com/idontexit" # pylint: disable=protected-access self.assertEqual(g.osinfo.name, "generic") + @utils.run_without_testsuite_hacks def test_dir_searchable(self): # Normally the dir searchable test is skipped in the unittest, # but let's contrive an example that should trigger all the code # to ensure it isn't horribly broken from virtinst import diskbackend - oldtest = os.environ.pop("VIRTINST_TEST_SUITE") - try: - uid = -1 - username = "fakeuser-zzzz" - with tempfile.TemporaryDirectory() as tmpdir: - fixlist = diskbackend.is_path_searchable(tmpdir, uid, username) - self.assertTrue(bool(fixlist)) - errdict = diskbackend.set_dirs_searchable(fixlist, username) - self.assertTrue(not bool(errdict)) + uid = -1 + username = "fakeuser-zzzz" + with tempfile.TemporaryDirectory() as tmpdir: + fixlist = diskbackend.is_path_searchable(tmpdir, uid, username) + self.assertTrue(bool(fixlist)) + errdict = diskbackend.set_dirs_searchable(fixlist, username) + self.assertTrue(not bool(errdict)) - - import getpass - fixlist = diskbackend.is_path_searchable( - os.getcwd(), os.getuid(), getpass.getuser()) - self.assertTrue(not bool(fixlist)) - finally: - os.environ["VIRTINST_TEST_SUITE"] = oldtest + import getpass + fixlist = diskbackend.is_path_searchable( + os.getcwd(), os.getuid(), getpass.getuser()) + self.assertTrue(not bool(fixlist)) def test_nonpredicatble_generate(self): realconn = virtinst.cli.getConnection("test:///default")