Skip to content

Commit 0c0e9e8

Browse files
committed
Fix Windows path compatibility using tmp_path fixture
The previous fix still failed on Windows because Path() objects created from Unix-style paths (/tmp/file) are not equal to Path objects created from Windows-style paths (D:\tmp\file), even when comparing Path objects. Solution: Use pytest's tmp_path fixture to create platform-appropriate absolute paths for testing. This ensures the test works correctly on all platforms (Windows, Linux, macOS) by using real absolute paths from the filesystem. The test now verifies: 1. The path returned equals the path provided (using actual absolute paths) 2. The path is absolute (using path.is_absolute()) This approach is more robust and platform-agnostic.
1 parent 59b52df commit 0c0e9e8

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

tests/test_local_state.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,13 @@ def test_get_local_state_path_env_relative(self, monkeypatch):
225225
assert path.name == "custom_local.json"
226226
assert path.parent == Path.cwd()
227227

228-
def test_get_local_state_path_env_absolute(self, monkeypatch):
228+
def test_get_local_state_path_env_absolute(self, monkeypatch, tmp_path):
229229
"""Test absolute path from environment variable."""
230-
monkeypatch.setenv("CLI_AUDIT_LOCAL_FILE", "/tmp/local_state.json")
230+
absolute_path = tmp_path / "local_state.json"
231+
monkeypatch.setenv("CLI_AUDIT_LOCAL_FILE", str(absolute_path))
231232
path = get_local_state_path()
232-
assert path == Path("/tmp/local_state.json")
233+
assert path == absolute_path
234+
assert path.is_absolute()
233235

234236

235237
class TestLoadLocalState:

tests/test_upstream_cache.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,13 @@ def test_get_upstream_cache_path_env_relative(self, monkeypatch):
196196
assert path.name == "custom_upstream.json"
197197
assert path.parent == Path.cwd()
198198

199-
def test_get_upstream_cache_path_env_absolute(self, monkeypatch):
199+
def test_get_upstream_cache_path_env_absolute(self, monkeypatch, tmp_path):
200200
"""Test absolute path from environment variable."""
201-
monkeypatch.setenv("CLI_AUDIT_UPSTREAM_FILE", "/tmp/upstream.json")
201+
absolute_path = tmp_path / "upstream.json"
202+
monkeypatch.setenv("CLI_AUDIT_UPSTREAM_FILE", str(absolute_path))
202203
path = get_upstream_cache_path()
203-
assert path == Path("/tmp/upstream.json")
204+
assert path == absolute_path
205+
assert path.is_absolute()
204206

205207

206208
class TestLoadUpstreamCache:

0 commit comments

Comments
 (0)