Skip to content

Commit efebdda

Browse files
committed
TestDryRun: Refactor to use a setup fixture.
1 parent bfb964b commit efebdda

1 file changed

Lines changed: 13 additions & 26 deletions

File tree

tests/test_relink.py

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -529,8 +529,9 @@ def test_timing_logging(self, tmp_path, caplog, use_timing, should_log_timing):
529529
class TestDryRun:
530530
"""Test suite for dry-run functionality."""
531531

532-
def test_dry_run_no_changes(self, temp_dirs, caplog):
533-
"""Test that dry-run mode makes no actual changes."""
532+
@pytest.fixture
533+
def dry_run_setup(self, temp_dirs):
534+
"""Set up directories and files for dry-run tests."""
534535
source_dir, target_dir = temp_dirs
535536
username = os.environ["USER"]
536537

@@ -543,6 +544,12 @@ def test_dry_run_no_changes(self, temp_dirs, caplog):
543544
with open(target_file, "w", encoding="utf-8") as f:
544545
f.write("target content")
545546

547+
return source_dir, target_dir, source_file, target_file, username
548+
549+
def test_dry_run_no_changes(self, dry_run_setup, caplog):
550+
"""Test that dry-run mode makes no actual changes."""
551+
source_dir, target_dir, source_file, _, username = dry_run_setup
552+
546553
# Get original file info
547554
with open(source_file, "r", encoding="utf-8") as f:
548555
original_content = f.read()
@@ -561,19 +568,9 @@ def test_dry_run_no_changes(self, temp_dirs, caplog):
561568
assert f.read() == original_content
562569
assert os.path.islink(source_file) == original_is_link
563570

564-
def test_dry_run_shows_message(self, temp_dirs, caplog):
571+
def test_dry_run_shows_message(self, dry_run_setup, caplog):
565572
"""Test that dry-run mode shows what would be done."""
566-
source_dir, target_dir = temp_dirs
567-
username = os.environ["USER"]
568-
569-
# Create files
570-
source_file = os.path.join(source_dir, "test_file.txt")
571-
target_file = os.path.join(target_dir, "test_file.txt")
572-
573-
with open(source_file, "w", encoding="utf-8") as f:
574-
f.write("source")
575-
with open(target_file, "w", encoding="utf-8") as f:
576-
f.write("target")
573+
source_dir, target_dir, source_file, target_file, username = dry_run_setup
577574

578575
# Run in dry-run mode
579576
with caplog.at_level(logging.INFO):
@@ -586,19 +583,9 @@ def test_dry_run_shows_message(self, temp_dirs, caplog):
586583
assert "[DRY RUN] Would create symbolic link:" in caplog.text
587584
assert f"{source_file} -> {target_file}" in caplog.text
588585

589-
def test_dry_run_no_delete_or_create_messages(self, temp_dirs, caplog):
586+
def test_dry_run_no_delete_or_create_messages(self, dry_run_setup, caplog):
590587
"""Test that dry-run doesn't show delete/create messages."""
591-
source_dir, target_dir = temp_dirs
592-
username = os.environ["USER"]
593-
594-
# Create files
595-
source_file = os.path.join(source_dir, "test_file.txt")
596-
target_file = os.path.join(target_dir, "test_file.txt")
597-
598-
with open(source_file, "w", encoding="utf-8") as f:
599-
f.write("source")
600-
with open(target_file, "w", encoding="utf-8") as f:
601-
f.write("target")
588+
source_dir, target_dir, _, _, username = dry_run_setup
602589

603590
# Run in dry-run mode
604591
with caplog.at_level(logging.INFO):

0 commit comments

Comments
 (0)