Closed zpuskas closed 2 years ago
Offending test entries seem to be:
Obtained by running tests with the following modification:
>>> git diff
diff --git a/tests/support.py b/tests/support.py
index afbb402..039ce40 100644
--- a/tests/support.py
+++ b/tests/support.py
@@ -1,6 +1,7 @@
import os
import shutil
import tempfile
+import inspect
def list_trash_dir(trash_dir_path):
@@ -34,4 +35,6 @@ class MyPath(str):
@classmethod
def make_temp_dir(cls):
- return cls(os.path.realpath(tempfile.mkdtemp()))
+ stack = inspect.stack()
+ the_class = stack[1][0].f_locals["self"].__class__.__name__
+ return cls(os.path.realpath(tempfile.mkdtemp(suffix=f"-{the_class}-trash_cli_test")))
and then running:
>>> yes| python -m unittest discover -v
>>> ls -1 /tmp | grep trash_cli_test | cut -d'-' -f2 | sort -u
PR #219 should be considered a band aid solution, since it won't prevent similar issues from happening in the future. The proper way to fix this permanently would be to create a tool specific test class:
class TrashCliTestCase(unittest.TestCase):
def setUp(self):
self.tmp_dir = MyPath.make_temp_dir()
def tearDown(self):
self.tmp_dir.clean_up()
And then update relevant tests to be a child of this class. Example:
class TestTrashEmptyCmd(TrashCliTestCase):
If a test needs additional things to happen in the setUp()/tearDown() then simply use super() to make sure the parent functionality is executed, e.g.:
class TestSomething(TrashCliTestCase):
def setUp(self):
super().setUp()
self.more_stuff = foo()
Your band aid solution is more than good. Merged
Describe the bug Running tests leaves behind temp directories, some of them are empty, some contain some test directories and files.
trash-cli version trash 0.21.10.24
Operating system:
To Reproduce
Expected behavior After running tests full clean up should include removing the top level temporary directory.