From 937c70c3a86b460ff0d8dcc330340cc833e0b060 Mon Sep 17 00:00:00 2001 From: Lie Ryan Date: Fri, 16 Dec 2022 01:52:42 +1100 Subject: [PATCH 1/2] Fix these test sometimes leaves files behind in the current working directory Also, convert the test to pytest style test since the test was essentially re-written from scratch anyway. --- ropetest/projecttest.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/ropetest/projecttest.py b/ropetest/projecttest.py index aa42c4e7d..5bd91429e 100644 --- a/ropetest/projecttest.py +++ b/ropetest/projecttest.py @@ -1,4 +1,5 @@ import os.path +import pathlib import tempfile import unittest from textwrap import dedent @@ -67,22 +68,23 @@ def test_creating_files_that_already_exist(self): self.project.root.create_file(self.sample_file) def test_making_root_folder_if_it_does_not_exist(self): - project = Project("sampleproject2") - try: - self.assertTrue( - os.path.exists("sampleproject2") and os.path.isdir("sampleproject2") - ) - finally: - testutils.remove_project(project) + with tempfile.TemporaryDirectory(dir=testutils.RUN_TMP_DIR) as tmpdir: + project_root = pathlib.Path(tmpdir) / "sampleproject2" + assert not project_root.exists() + + project = Project(project_root) + + assert project_root.exists() + assert project_root.is_dir() def test_failure_when_project_root_exists_and_is_a_file(self): - project_root = "sampleproject2" - try: - open(project_root, "w").close() + with tempfile.TemporaryDirectory(dir=testutils.RUN_TMP_DIR) as tmpdir: + project_root = pathlib.Path(tmpdir) / "sampleproject2" + project_root.touch() + assert project_root.exists() and project_root.is_file() + with self.assertRaises(RopeError): Project(project_root) - finally: - testutils.remove_recursively(project_root) def test_creating_folders(self): folderName = "SampleFolder" From 637bb9eb4d33c4c8aee4a5992c159738ec3978b9 Mon Sep 17 00:00:00 2001 From: Lie Ryan Date: Fri, 16 Dec 2022 15:42:34 +1100 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f9b892fbc..65a011bc0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # **Upcoming release** +- #604 Fix test that sometimes leaves files behind in the current working directory (@lieryan) # Release 1.6.0