Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write inline snapshots with atomic rename #373

Merged
merged 2 commits into from Jun 3, 2023

Conversation

max-sixty
Copy link
Sponsor Contributor

I'm occasionally seeing a chunk of the file cut off when using insta with https://dystroy.org/bacon/, which restarts on any file change. The proposed code does an atomic rename, preventing this.

It does add a dependency though, so up to you on the tradeoff.

I'm occasionally seeing a chunk of the file cut off when using insta with https://dystroy.org/bacon/. This does an atomic rename.

It does add a dependency though, so up to you on the tradeoff.
cargo-insta/src/inline.rs Outdated Show resolved Hide resolved
@max-sixty max-sixty requested a review from mitsuhiko June 3, 2023 20:04
@max-sixty
Copy link
Sponsor Contributor Author

One aspect to highlight — though this doesn't change the existing behavior — it will overwrite the file even if it's been edited by the user. This can happen when using review, and the file is edited while it's waiting for input, or when someone is running tests in a loop. I've had this happen a couple of times.

We could add a check that there has been no change to the file; I do this in https://github.com/max-sixty/pytest-accept.

@mitsuhiko mitsuhiko merged commit 3dcb42b into mitsuhiko:master Jun 3, 2023
@max-sixty max-sixty deleted the atomic-write branch June 3, 2023 21:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants