Skip to content

Commit e4e9026

Browse files
committed
test_relink: Refactor to module-level fixture_temp_dirs().
1 parent dab7954 commit e4e9026

1 file changed

Lines changed: 12 additions & 35 deletions

File tree

tests/test_relink.py

Lines changed: 12 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,21 @@ def fixture_mock_default_dirs():
4848
shutil.rmtree(target_dir, ignore_errors=True)
4949

5050

51-
class TestFindAndReplaceOwnedFiles:
52-
"""Test suite for find_and_replace_owned_files function."""
51+
@pytest.fixture(scope="function", name="temp_dirs")
52+
def fixture_temp_dirs():
53+
"""Create temporary source and target directories for testing."""
54+
source_dir = tempfile.mkdtemp(prefix="test_source_")
55+
target_dir = tempfile.mkdtemp(prefix="test_target_")
5356

54-
@pytest.fixture
55-
def temp_dirs(self):
56-
"""Create temporary source and target directories for testing."""
57-
source_dir = tempfile.mkdtemp(prefix="test_source_")
58-
target_dir = tempfile.mkdtemp(prefix="test_target_")
57+
yield source_dir, target_dir
58+
59+
# Cleanup
60+
shutil.rmtree(source_dir, ignore_errors=True)
61+
shutil.rmtree(target_dir, ignore_errors=True)
5962

60-
yield source_dir, target_dir
6163

62-
# Cleanup
63-
shutil.rmtree(source_dir, ignore_errors=True)
64-
shutil.rmtree(target_dir, ignore_errors=True)
64+
class TestFindAndReplaceOwnedFiles:
65+
"""Test suite for find_and_replace_owned_files function."""
6566

6667
@pytest.fixture
6768
def current_user(self):
@@ -482,18 +483,6 @@ def test_timing_default(self, mock_default_dirs):
482483
class TestTiming:
483484
"""Test suite for timing functionality."""
484485

485-
@pytest.fixture
486-
def temp_dirs(self):
487-
"""Create temporary source and target directories for testing."""
488-
source_dir = tempfile.mkdtemp(prefix="test_source_")
489-
target_dir = tempfile.mkdtemp(prefix="test_target_")
490-
491-
yield source_dir, target_dir
492-
493-
# Cleanup
494-
shutil.rmtree(source_dir, ignore_errors=True)
495-
shutil.rmtree(target_dir, ignore_errors=True)
496-
497486
def test_timing_message_logged(self, tmp_path, caplog):
498487
"""Test that timing message is logged when timing is enabled."""
499488
# Create real directories
@@ -558,18 +547,6 @@ def test_timing_not_logged_by_default(self, tmp_path, caplog):
558547
class TestDryRun:
559548
"""Test suite for dry-run functionality."""
560549

561-
@pytest.fixture
562-
def temp_dirs(self):
563-
"""Create temporary source and target directories for testing."""
564-
source_dir = tempfile.mkdtemp(prefix="test_source_")
565-
target_dir = tempfile.mkdtemp(prefix="test_target_")
566-
567-
yield source_dir, target_dir
568-
569-
# Cleanup
570-
shutil.rmtree(source_dir, ignore_errors=True)
571-
shutil.rmtree(target_dir, ignore_errors=True)
572-
573550
def test_dry_run_no_changes(self, temp_dirs, caplog):
574551
"""Test that dry-run mode makes no actual changes."""
575552
source_dir, target_dir = temp_dirs

0 commit comments

Comments
 (0)