From c83493953839da2d0ae06c094984e7a90af215dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mark=C3=A9ta?= Date: Fri, 2 Aug 2024 11:53:29 +0200 Subject: [PATCH] Revert "Use tmp_path in ghostwriter tests" This reverts commit 769f5750b6bdbdccfd8b8b34c5f9b72196744421. --- .../tests/ghostwriter/test_ghostwriter.py | 36 ++++++++----------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/tests/ghostwriter/test_ghostwriter.py b/tests/ghostwriter/test_ghostwriter.py index ddee5e78f..7bad9f081 100644 --- a/tests/ghostwriter/test_ghostwriter.py +++ b/tests/ghostwriter/test_ghostwriter.py @@ -11,7 +11,6 @@ import ast import enum import json -import os import platform import re import socket @@ -452,22 +451,13 @@ def test_get_imports_for_strategy(strategy, imports): @pytest.fixture -def in_temp_path(tmp_path): - """Fixture to execute tests in a temporary path.""" - old_path = Path.cwd() - os.chdir(tmp_path) - yield - os.chdir(old_path) - - -@pytest.fixture -def temp_script_file(in_temp_path): - """Fixture to create a script file in a temporary working directory. - - Changes the working directory to a temporary directory, then yields an extant file - whose name will end in .py and which includes an importable function. +def temp_script_file(): + """Fixture to yield a Path to a temporary file in the local directory. File name will end + in .py and will include an importable function. """ p = Path("my_temp_script.py") + if p.exists(): + raise FileExistsError(f"Did not expect {p} to exist during testing") p.write_text( dedent( """ @@ -477,17 +467,18 @@ def temp_script_file(in_temp_path): ), encoding="utf-8", ) - return p + yield p + p.unlink() @pytest.fixture -def temp_script_file_with_py_function(in_temp_path): - """Fixture to create a python file in a temporary working directory. - - Changes the working directory to a temporary directory, then yields an extant file - whose name will end in .py and which includes an importable function named "py". +def temp_script_file_with_py_function(): + """Fixture to yield a Path to a temporary file in the local directory. File name will end + in .py and will include an importable function named "py" """ p = Path("my_temp_script_with_py_function.py") + if p.exists(): + raise FileExistsError(f"Did not expect {p} to exist during testing") p.write_text( dedent( """ @@ -497,7 +488,8 @@ def temp_script_file_with_py_function(in_temp_path): ), encoding="utf-8", ) - return p + yield p + p.unlink() def test_obj_name(temp_script_file, temp_script_file_with_py_function): -- 2.45.2