From b00662fa4ab863958707e937de25c9a3296dd6c5 Mon Sep 17 00:00:00 2001 From: Sassan Haradji Date: Mon, 27 May 2024 04:14:28 +0400 Subject: [PATCH] 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: https://github.com/pytest-dev/pyfakefs/issues/1021#issuecomment-2132438234 --- CHANGELOG.md | 6 ++++++ pyproject.toml | 2 +- redux_pytest/fixtures/__init__.py | 12 +++++++----- redux_pytest/fixtures/snapshot.py | 5 +++-- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d745f0..e951203 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Version 0.15.6 + +- 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()` + ## Version 0.15.5 - feat(test-snapshot): while still taking snapshots of the whole state of the diff --git a/pyproject.toml b/pyproject.toml index 2eb478e..76bb0ec 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "python-redux" -version = "0.15.5" +version = "0.15.6" description = "Redux implementation for Python" authors = ["Sassan Haradji "] license = "Apache-2.0" diff --git a/redux_pytest/fixtures/__init__.py b/redux_pytest/fixtures/__init__.py index 78eb6ba..6939d66 100644 --- a/redux_pytest/fixtures/__init__.py +++ b/redux_pytest/fixtures/__init__.py @@ -2,11 +2,13 @@ import pytest -pytest.register_assert_rewrite('redux_pytest.fixtures.event_loop') -pytest.register_assert_rewrite('redux_pytest.fixtures.monitor') -pytest.register_assert_rewrite('redux_pytest.fixtures.snapshot') -pytest.register_assert_rewrite('redux_pytest.fixtures.store') -pytest.register_assert_rewrite('redux_pytest.fixtures.wait_for') +pytest.register_assert_rewrite( + 'redux_pytest.fixtures.event_loop', + 'redux_pytest.fixtures.monitor', + 'redux_pytest.fixtures.snapshot', + 'redux_pytest.fixtures.store', + 'redux_pytest.fixtures.wait_for', +) from .event_loop import LoopThread, event_loop # noqa: E402 from .monitor import StoreMonitor, store_monitor # noqa: E402 diff --git a/redux_pytest/fixtures/snapshot.py b/redux_pytest/fixtures/snapshot.py index 518c75c..8e0b899 100644 --- a/redux_pytest/fixtures/snapshot.py +++ b/redux_pytest/fixtures/snapshot.py @@ -95,9 +95,10 @@ def take( if self.override: json_path.write_text(f'// {filename}\n{new_snapshot}\n') # pragma: no cover else: - old_snapshot = None - if json_path.exists(): + try: old_snapshot = json_path.read_text().split('\n', 1)[1][:-1] + except Exception: # noqa: BLE001 + old_snapshot = None if old_snapshot != new_snapshot: self._is_failed = True mismatch_path.write_text( # pragma: no cover