diff options
author | Zac Medico <zmedico@gentoo.org> | 2024-02-26 20:02:28 -0800 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2024-02-26 20:03:07 -0800 |
commit | e9bdb7342b3048ab3236bff9d94ce733bb877d8e (patch) | |
tree | f7a50d5d4be0e4816f34961f7ab1e490e0634907 /lib | |
parent | Scheduler: Support parallel-install with merge-wait (diff) | |
download | portage-e9bdb7342b3048ab3236bff9d94ce733bb877d8e.tar.gz portage-e9bdb7342b3048ab3236bff9d94ce733bb877d8e.tar.bz2 portage-e9bdb7342b3048ab3236bff9d94ce733bb877d8e.zip |
BinarytreeTestCase: Use temporary TMPDIR
Create a temporary TMPDIR which prevents test methods of this
class from leaving behind an empty /tmp/Packages file if TMPDIR
is initially unset.
Signed-off-by: Zac Medico <zmedico@gentoo.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/portage/tests/dbapi/test_bintree.py | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/lib/portage/tests/dbapi/test_bintree.py b/lib/portage/tests/dbapi/test_bintree.py index 018f1cf9b..91ac338a0 100644 --- a/lib/portage/tests/dbapi/test_bintree.py +++ b/lib/portage/tests/dbapi/test_bintree.py @@ -1,4 +1,4 @@ -# Copyright 2022 Gentoo Authors +# Copyright 2022-2024 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 from unittest.mock import MagicMock, patch, call @@ -13,6 +13,26 @@ from portage.const import BINREPOS_CONF_FILE class BinarytreeTestCase(TestCase): + @classmethod + def setUpClass(cls): + """ + Create a temporary TMPDIR which prevents test + methods of this class from leaving behind an empty + /tmp/Packages file if TMPDIR is initially unset. + """ + cls._orig_tmpdir = os.environ.get("TMPDIR") + cls._tmpdir = tempfile.TemporaryDirectory() + os.environ["TMPDIR"] = cls._tmpdir.name + + @classmethod + def tearDownClass(cls): + cls._tmpdir.cleanup() + if cls._orig_tmpdir is None: + os.environ.pop("TMPDIR", None) + else: + os.environ["TMPDIR"] = cls._orig_tmpdir + del cls._orig_tmpdir, cls._tmpdir + def test_required_init_params(self): with self.assertRaises(TypeError) as cm: binarytree() |