Skip to content

Commit e1eaaef

Browse files
committed
refactor(test-snapshot): make it aligned with pyfakefs by using try/except instead of checking Path().exists() as pyfakefs doesn't seem to respect skip_names for Path().exists()
relevant: pytest-dev/pyfakefs#1021 (comment)
1 parent b7e020f commit e1eaaef

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Version 0.15.7
4+
5+
- refactor(test-snapshot): make it aligned with `pyfakefs` by using `try`/`except`
6+
instead of checking `Path().exists()` as `pyfakefs` doesn't seem to respect `skip_names`
7+
for `Path().exists()`
8+
39
## Version 0.15.5
410

511
- feat(test-snapshot): while still taking snapshots of the whole state of the

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "python-redux"
3-
version = "0.15.5"
3+
version = "0.15.7"
44
description = "Redux implementation for Python"
55
authors = ["Sassan Haradji <[email protected]>"]
66
license = "Apache-2.0"

redux_pytest/fixtures/__init__.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
import pytest
44

5-
pytest.register_assert_rewrite('redux_pytest.fixtures.event_loop')
6-
pytest.register_assert_rewrite('redux_pytest.fixtures.monitor')
7-
pytest.register_assert_rewrite('redux_pytest.fixtures.snapshot')
8-
pytest.register_assert_rewrite('redux_pytest.fixtures.store')
9-
pytest.register_assert_rewrite('redux_pytest.fixtures.wait_for')
5+
pytest.register_assert_rewrite(
6+
'redux_pytest.fixtures.event_loop',
7+
'redux_pytest.fixtures.monitor',
8+
'redux_pytest.fixtures.snapshot',
9+
'redux_pytest.fixtures.store',
10+
'redux_pytest.fixtures.wait_for',
11+
)
1012

1113
from .event_loop import LoopThread, event_loop # noqa: E402
1214
from .monitor import StoreMonitor, store_monitor # noqa: E402

redux_pytest/fixtures/snapshot.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,21 @@ def take(
8686
)
8787
raise RuntimeError(msg)
8888

89+
from pathlib import Path
90+
8991
filename = self.get_filename(title)
90-
path = self.results_dir / filename
92+
path = Path(self.results_dir / filename)
9193
json_path = path.with_suffix('.jsonc')
9294
mismatch_path = path.with_suffix('.mismatch.jsonc')
9395

9496
new_snapshot = self.json_snapshot(selector=selector)
9597
if self.override:
9698
json_path.write_text(f'// {filename}\n{new_snapshot}\n') # pragma: no cover
9799
else:
98-
old_snapshot = None
99-
if json_path.exists():
100+
try:
100101
old_snapshot = json_path.read_text().split('\n', 1)[1][:-1]
102+
except Exception: # noqa: BLE001
103+
old_snapshot = None
101104
if old_snapshot != new_snapshot:
102105
self._is_failed = True
103106
mismatch_path.write_text( # pragma: no cover

0 commit comments

Comments
 (0)