From 604fe1c2755633b9d8db48d8d00cd0b460a63629 Mon Sep 17 00:00:00 2001 From: proletarius101 Date: Wed, 5 Jun 2024 18:33:40 +0800 Subject: [PATCH] test(deploy): fix directory exists error when running tests the second time --- tests/deploy.TestCase | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/tests/deploy.TestCase b/tests/deploy.TestCase index 35697548..00a62888 100755 --- a/tests/deploy.TestCase +++ b/tests/deploy.TestCase @@ -539,13 +539,6 @@ class DeployTest(unittest.TestCase): url = "example.com:/var/www/fdroid" repo_section = 'archive' - os.mkdir(repo_section) - fake_files = fdroidserver.deploy.INDEX_FILES - for filename in fake_files: - fake_file = Path(repo_section) / filename - with fake_file.open('w') as fp: - fp.write('not a real one, but has the right filename') - # setup function for asserting subprocess.call invocations call_iteration = 0 @@ -597,10 +590,18 @@ class DeployTest(unittest.TestCase): call_iteration += 1 return 0 - with mock.patch('subprocess.call', side_effect=update_server_webroot_call): - fdroidserver.deploy.update_serverwebroot( - {'url': url, 'index_only': True}, repo_section - ) + with tempfile.TemporaryDirectory() as tmpdir, TmpCwd(tmpdir): + with mock.patch('subprocess.call', side_effect=update_server_webroot_call): + os.mkdir(repo_section) + fake_files = fdroidserver.deploy.INDEX_FILES + for filename in fake_files: + fake_file = Path(repo_section) / filename + with fake_file.open('w') as fp: + fp.write('not a real one, but has the right filename') + + fdroidserver.deploy.update_serverwebroot( + {'url': url, 'index_only': True}, repo_section + ) self.assertEqual(call_iteration, 1, 'expected 1 invocations of subprocess.call') @unittest.skipIf(