From e1e4fd707f3f906a1c23f52c987f8b04b0dfab63 Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Mon, 20 Jul 2020 02:08:23 -0700 Subject: [PATCH] Used context manager version of tempfile.TemporaryDirectory() in utils_tests.test_autoreload. --- tests/utils_tests/test_autoreload.py | 34 +++++++++++++--------------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/tests/utils_tests/test_autoreload.py b/tests/utils_tests/test_autoreload.py index 72ae20ac12..5b1a733b47 100644 --- a/tests/utils_tests/test_autoreload.py +++ b/tests/utils_tests/test_autoreload.py @@ -173,27 +173,25 @@ class TestChildArguments(SimpleTestCase): @mock.patch('sys.warnoptions', []) def test_exe_fallback(self): - tmpdir = tempfile.TemporaryDirectory() - self.addCleanup(tmpdir.cleanup) - exe_path = Path(tmpdir.name) / 'django-admin.exe' - exe_path.touch() - with mock.patch('sys.argv', [exe_path.with_suffix(''), 'runserver']): - self.assertEqual( - autoreload.get_child_arguments(), - [exe_path, 'runserver'] - ) + with tempfile.TemporaryDirectory() as tmpdir: + exe_path = Path(tmpdir) / 'django-admin.exe' + exe_path.touch() + with mock.patch('sys.argv', [exe_path.with_suffix(''), 'runserver']): + self.assertEqual( + autoreload.get_child_arguments(), + [exe_path, 'runserver'] + ) @mock.patch('sys.warnoptions', []) def test_entrypoint_fallback(self): - tmpdir = tempfile.TemporaryDirectory() - self.addCleanup(tmpdir.cleanup) - script_path = Path(tmpdir.name) / 'django-admin-script.py' - script_path.touch() - with mock.patch('sys.argv', [script_path.with_name('django-admin'), 'runserver']): - self.assertEqual( - autoreload.get_child_arguments(), - [sys.executable, script_path, 'runserver'] - ) + with tempfile.TemporaryDirectory() as tmpdir: + script_path = Path(tmpdir) / 'django-admin-script.py' + script_path.touch() + with mock.patch('sys.argv', [script_path.with_name('django-admin'), 'runserver']): + self.assertEqual( + autoreload.get_child_arguments(), + [sys.executable, script_path, 'runserver'] + ) @mock.patch('sys.argv', ['does-not-exist', 'runserver']) @mock.patch('sys.warnoptions', [])