From 7ecc9fe97bc6fd5eef2191f48a42949813c04076 Mon Sep 17 00:00:00 2001 From: Matt Bachmann Date: Tue, 17 Jan 2023 21:05:05 -0500 Subject: [PATCH 1/2] Mocking os path and using TEMPDIR has interacting effects. We need to try and ensure the patch is cleaned up before the tempdir is cleaned up --- tests/test_diff_reporter.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/test_diff_reporter.py b/tests/test_diff_reporter.py index 700ae437..77498e38 100644 --- a/tests/test_diff_reporter.py +++ b/tests/test_diff_reporter.py @@ -6,6 +6,7 @@ import tempfile from pathlib import Path from textwrap import dedent +from unittest.mock import patch import pytest @@ -96,7 +97,7 @@ def test_name_include_untracked(git_diff): ), ], ) -def test_git_path_selection(mocker, diff, git_diff, include, exclude, expected): +def test_git_path_selection(diff, git_diff, include, exclude, expected): old_cwd = os.getcwd() with tempfile.TemporaryDirectory() as tmp_dir: # change the working directory into the temp directory so that globs are working @@ -127,8 +128,8 @@ def test_git_path_selection(mocker, diff, git_diff, include, exclude, expected): ) # Get the source paths in the diff - mocker.patch.object(os.path, "abspath", lambda path: f"{tmp_dir}/{path}") - source_paths = diff.src_paths_changed() + with patch.object(os.path, "abspath", lambda path: f"{tmp_dir}/{path}"): + source_paths = diff.src_paths_changed() # Validate the source paths # They should be in alphabetical order From 2595bc440d7e62c47c4398aebf2856ccd8cd5dfa Mon Sep 17 00:00:00 2001 From: Matt Bachmann Date: Wed, 18 Jan 2023 09:35:03 -0500 Subject: [PATCH 2/2] Change dirs within the context manager so we are not deleting the directory we are currently in when we clean up --- tests/test_diff_reporter.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_diff_reporter.py b/tests/test_diff_reporter.py index 77498e38..12a63219 100644 --- a/tests/test_diff_reporter.py +++ b/tests/test_diff_reporter.py @@ -135,8 +135,8 @@ def test_git_path_selection(diff, git_diff, include, exclude, expected): # They should be in alphabetical order assert source_paths == expected - # change back to the previous working directory - os.chdir(old_cwd) + # change back to the previous working directory + os.chdir(old_cwd) def test_git_source_paths(diff, git_diff):