Skip to content

Commit

Permalink
collect snapshot file set into single message
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
  • Loading branch information
wagoodman committed Oct 18, 2023
1 parent 055ae95 commit a5f1e27
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,40 @@ def copy_input_fixtures(self, mock_data_path: str):

def assert_result_snapshots(self):
expected_files_to_test = set(self._snapshot_files())
missing_snapshot_files = []

for result_file in self.result_files():
# protection against test configuration not swapping to the flat file store strategy
assert result_file.endswith(".json")

with open(result_file) as f:
snapshot_path = result_file.split("results/")[-1]
self.snapshot.assert_match(f.read() + "\n", snapshot_path)

snapshot_abs_path = os.path.join(self.snapshot.snapshot_dir, snapshot_path)
if snapshot_abs_path in expected_files_to_test:
expected_files_to_test.remove(snapshot_abs_path)

for expected_snapshot_path in expected_files_to_test:
assert False, f"snapshot not asserted for {expected_snapshot_path}"
if not self.snapshot._snapshot_update and not os.path.exists(snapshot_abs_path):
missing_snapshot_files.append(snapshot_abs_path)
else:
self.snapshot.assert_match(f.read() + "\n", snapshot_path)

if snapshot_abs_path in expected_files_to_test:
expected_files_to_test.remove(snapshot_abs_path)

message_lines = []
if expected_files_to_test:
message_lines.append("existing snapshot files that were not asserted:")
for expected_snapshot_path in expected_files_to_test:
message_lines.append(f" - {expected_snapshot_path}")

if missing_snapshot_files:
if message_lines:
message_lines.append("")
message_lines.append("missing snapshot files:")
for missing_snapshot_file in missing_snapshot_files:
message_lines.append(f" - {missing_snapshot_file}")

if message_lines:
pytest.fail("\n".join(message_lines), pytrace=False)


def load_json_schema(path: str) -> dict:
Expand Down

0 comments on commit a5f1e27

Please sign in to comment.