From 09f79e5a42e61259e8f547b1a98a363ef55efa4b Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Thu, 6 Jul 2023 12:37:32 -0700 Subject: [PATCH] fix PermErr in test on windows --- tests/test_coder.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/test_coder.py b/tests/test_coder.py index d34e52d4e..b1be19eea 100644 --- a/tests/test_coder.py +++ b/tests/test_coder.py @@ -1,6 +1,7 @@ import os import tempfile import unittest +from pathlib import Path from unittest.mock import MagicMock, patch import openai @@ -182,8 +183,14 @@ class TestCoder(unittest.TestCase): def test_run_with_file_deletion(self): # Create a few temporary files - _, file1 = tempfile.mkstemp() - _, file2 = tempfile.mkstemp() + + tempdir = Path(tempfile.mkdtemp()) + + file1 = tempdir / "file1.txt" + file2 = tempdir / "file2.txt" + + file1.touch() + file2.touch() files = [file1, file2] @@ -202,7 +209,7 @@ class TestCoder(unittest.TestCase): coder.run(with_message="hi") self.assertEqual(len(coder.abs_fnames), 2) - os.remove(file1) + file1.unlink() # Call the run method again with a message coder.run(with_message="hi")