diff --git a/inline_snapshot/_external.py b/inline_snapshot/_external.py index 0051147b..2aa0775b 100644 --- a/inline_snapshot/_external.py +++ b/inline_snapshot/_external.py @@ -44,7 +44,10 @@ def list(self) -> Set[str]: return set() def persist(self, name): - file = self._lookup_path(name) + try: + file = self._lookup_path(name) + except HashError: + return if file.stem.endswith("-new"): stem = file.stem[:-4] file.rename(file.with_name(stem + file.suffix)) diff --git a/inline_snapshot/pytest_plugin.py b/inline_snapshot/pytest_plugin.py index 396dcf85..1dfaafc9 100644 --- a/inline_snapshot/pytest_plugin.py +++ b/inline_snapshot/pytest_plugin.py @@ -35,6 +35,13 @@ def pytest_addoption(parser): ) +def xdist_running(config): + return ( + hasattr(config.option, "numprocesses") + and config.option.numprocesses is not None + ) + + def pytest_configure(config): flags = config.option.inline_snapshot.split(",") flags = [flag for flag in flags if flag] @@ -44,7 +51,12 @@ def pytest_configure(config): f"--inline-snapshot-disable can not be combined with other flags ({','.join(flags)})" ) - _inline_snapshot._active = not config.option.inline_snapshot_disable + if xdist_running(config) and flags: + raise pytest.UsageError(f"inline-snapshot can not be combined with xdist") + + _inline_snapshot._active = not ( + config.option.inline_snapshot_disable or xdist_running(config) + ) _inline_snapshot._update_flags = _inline_snapshot.Flags(set(flags)) @@ -116,6 +128,14 @@ def pytest_assertrepr_compare(config, op, left, right): def pytest_terminal_summary(terminalreporter, exitstatus, config): + + if xdist_running(config): + terminalreporter.section("inline snapshot") + terminalreporter.write( + "INFO: inline-snapshot was disabled because you used xdist\n" + ) + return + if not _inline_snapshot._active: return @@ -157,6 +177,7 @@ def report(flag, message): ) if _inline_snapshot._update_flags.change_something(): + count = {"create": 0, "fix": 0, "trim": 0, "update": 0} for snapshot in _inline_snapshot.snapshots.values(): diff --git a/tests/test_pytest_plugin.py b/tests/test_pytest_plugin.py index 6066992d..db4882a4 100644 --- a/tests/test_pytest_plugin.py +++ b/tests/test_pytest_plugin.py @@ -360,3 +360,29 @@ def test_sub_snapshot(): ================================================================== 1 passed, 1 error in