From 1fe460ea2d1339358ea9cd4c909151ed7eccdcfc Mon Sep 17 00:00:00 2001
From: Elena ``of Valhalla'' Grandi <valhalla@trueelena.org>
Date: Thu, 4 Aug 2022 17:18:11 +0200
Subject: Explicitely close another missing temporary directory

---
 tests/test_commands.py | 42 +++++++++++++++++++++---------------------
 1 file changed, 21 insertions(+), 21 deletions(-)

(limited to 'tests')

diff --git a/tests/test_commands.py b/tests/test_commands.py
index 9cd5c88..d52908a 100644
--- a/tests/test_commands.py
+++ b/tests/test_commands.py
@@ -145,27 +145,27 @@ class testCommandsSimple(unittest.TestCase, CommandsMixin):
         self.assertEqual(streams['stderr'].getvalue(), '')
 
     def test_export(self):
-        dest_tmpdir = tempfile.TemporaryDirectory()
-        utils.copytree(
-            'tests/data/simple',
-            dest_tmpdir.name,
-            dirs_exist_ok=True,
-        )
-        # TODO: make finding the templates less prone to breaking and
-        # then remove the cwd change from here
-        old_cwd = os.getcwd()
-        os.chdir(self.tmpdir.name)
-        args = {
-            'collection': self.tmpdir.name,
-            'git': True,
-            'template': 'templates/from_self.yaml',
-            'query': 'Another',
-            'destination': dest_tmpdir.name,
-        }
-        streams = self._run_command(command.Export(), args)
-        os.chdir(old_cwd)
-        self.assertEqual(streams['stdout'].getvalue(), '')
-        self.assertEqual(streams['stderr'].getvalue(), '')
+        with tempfile.TemporaryDirectory() as dest_tmpdir:
+            utils.copytree(
+                'tests/data/simple',
+                dest_tmpdir,
+                dirs_exist_ok=True,
+            )
+            # TODO: make finding the templates less prone to breaking and
+            # then remove the cwd change from here
+            old_cwd = os.getcwd()
+            os.chdir(self.tmpdir.name)
+            args = {
+                'collection': self.tmpdir.name,
+                'git': True,
+                'template': 'templates/from_self.yaml',
+                'query': 'Another',
+                'destination': dest_tmpdir,
+            }
+            streams = self._run_command(command.Export(), args)
+            os.chdir(old_cwd)
+            self.assertEqual(streams['stdout'].getvalue(), '')
+            self.assertEqual(streams['stderr'].getvalue(), '')
 
     def test_remove(self):
         args = {
-- 
cgit v1.2.3