Skip to content

Commit

Permalink
fix deletion of file content on snapshot error
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikschubert committed Mar 17, 2023
1 parent 3cb5069 commit 74c44e1
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions localstack/testing/snapshots/prototype.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ def _persist_state(self) -> None:
with open(self.file_path, "r+") as fd:
try:
content = fd.read()
fd.seek(0)
fd.truncate()
full_state = json.loads(content or "{}")
recorded = {
"recorded-date": datetime.now().strftime("%d-%m-%Y, %H:%M:%S"),
"recorded-content": self.observed_state,
}
full_state[self.scope_key] = recorded
state_to_dump = json.dumps(full_state, indent=2)
fd.seek(0)
fd.truncate()
# add line ending to be compatible with pre-commit-hooks (end-of-file-fixer)
fd.write(f"{state_to_dump}\n")
except Exception as e:
Expand Down

0 comments on commit 74c44e1

Please sign in to comment.