Skip to content

Commit 3a7b50c

Browse files
committed
relink tests: Move some fixtures to conftest.py.
1 parent 633669f commit 3a7b50c

4 files changed

Lines changed: 29 additions & 54 deletions

File tree

tests/relink/conftest.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"""
2+
Shared fixtures for relink tests.
3+
"""
4+
5+
import os
6+
import tempfile
7+
import shutil
8+
9+
import pytest
10+
11+
12+
@pytest.fixture(scope="function", name="temp_dirs")
13+
def fixture_temp_dirs():
14+
"""Create temporary source and target directories for testing."""
15+
source_dir = tempfile.mkdtemp(prefix="test_source_")
16+
target_dir = tempfile.mkdtemp(prefix="test_target_")
17+
18+
yield source_dir, target_dir
19+
20+
# Cleanup
21+
shutil.rmtree(source_dir, ignore_errors=True)
22+
shutil.rmtree(target_dir, ignore_errors=True)
23+
24+
25+
@pytest.fixture(name="current_user")
26+
def fixture_current_user():
27+
"""Get the current user's username."""
28+
username = os.environ["USER"]
29+
return username

tests/relink/test_dryrun.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
import os
66
import sys
7-
import tempfile
8-
import shutil
97
import logging
108

119
import pytest
@@ -18,19 +16,6 @@
1816
import relink # noqa: E402
1917

2018

21-
@pytest.fixture(scope="function", name="temp_dirs")
22-
def fixture_temp_dirs():
23-
"""Create temporary source and target directories for testing."""
24-
source_dir = tempfile.mkdtemp(prefix="test_source_")
25-
target_dir = tempfile.mkdtemp(prefix="test_target_")
26-
27-
yield source_dir, target_dir
28-
29-
# Cleanup
30-
shutil.rmtree(source_dir, ignore_errors=True)
31-
shutil.rmtree(target_dir, ignore_errors=True)
32-
33-
3419
@pytest.fixture(name="dry_run_setup")
3520
def fixture_dry_run_setup(temp_dirs):
3621
"""Set up directories and files for dry-run tests."""

tests/relink/test_find_and_replace_owned_files.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,10 @@
55
import os
66
import sys
77
import tempfile
8-
import shutil
98
import pwd
109
import logging
1110
from unittest.mock import patch
1211

13-
import pytest
14-
1512
# Add parent directory to path to import relink module
1613
sys.path.insert(
1714
0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
@@ -20,26 +17,6 @@
2017
import relink # noqa: E402
2118

2219

23-
@pytest.fixture(scope="function", name="temp_dirs")
24-
def fixture_temp_dirs():
25-
"""Create temporary source and target directories for testing."""
26-
source_dir = tempfile.mkdtemp(prefix="test_source_")
27-
target_dir = tempfile.mkdtemp(prefix="test_target_")
28-
29-
yield source_dir, target_dir
30-
31-
# Cleanup
32-
shutil.rmtree(source_dir, ignore_errors=True)
33-
shutil.rmtree(target_dir, ignore_errors=True)
34-
35-
36-
@pytest.fixture(name="current_user")
37-
def fixture_current_user():
38-
"""Get the current user's username."""
39-
username = os.environ["USER"]
40-
return username
41-
42-
4320
def test_basic_file_replacement(temp_dirs, current_user):
4421
"""Test basic functionality: replace owned file with symlink."""
4522
source_dir, target_dir = temp_dirs

tests/relink/test_verbosity.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,9 @@
55
import os
66
import sys
77
import tempfile
8-
import shutil
98
import logging
109
from unittest.mock import patch
1110

12-
import pytest
13-
1411
# Add parent directory to path to import relink module
1512
sys.path.insert(
1613
0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
@@ -19,19 +16,6 @@
1916
import relink # noqa: E402
2017

2118

22-
@pytest.fixture(scope="function", name="temp_dirs")
23-
def fixture_temp_dirs():
24-
"""Create temporary source and target directories for testing."""
25-
source_dir = tempfile.mkdtemp(prefix="test_source_")
26-
target_dir = tempfile.mkdtemp(prefix="test_target_")
27-
28-
yield source_dir, target_dir
29-
30-
# Cleanup
31-
shutil.rmtree(source_dir, ignore_errors=True)
32-
shutil.rmtree(target_dir, ignore_errors=True)
33-
34-
3519
def test_quiet_mode_suppresses_info_messages(temp_dirs, caplog):
3620
"""Test that quiet mode suppresses INFO level messages."""
3721
source_dir, target_dir = temp_dirs

0 commit comments

Comments
 (0)