You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Feedback on responses._recorder / How to make it better #740
Disclosure: I maintain MockRelay, a different record/replay tool. Not trying to redirect the work here — your plugin is the right shape for a single-process library. One design question that cost me real time building the other thing, in case it's useful for the bundled plugin.
The hard part of "save responses to a file" isn't the saving, it's the identity.
In MockRelay a fixture's ID is derived from the request that produced it — upstream, method, path, query, and a hash of the redacted body. The consequence: recording the same endpoint twice with different responses overwrites one file. There is no ambiguity, it is deterministic, and it silently loses the second response.
That's the right default for a recorder whose job is "keep the fixture set current," and it's probably the wrong default for your plugin. In your snippet the filename is f"{f}.yaml" where f is request.node.name — so you're keying on the test node, which sidesteps the problem entirely by giving one snapshot per test. That's deliberate and good, but it means two tests hitting the same endpoint with different expected responses each get their own file, and you're never merging them. Whether that's a feature depends on what people are trying to fix with the plugin.
The trade-off in your favour is that per-test keying means no collision is even possible, and re-recording is always a straight overwrite. The risk is that a user with a shared helper called from three tests gets three near-duplicate snapshots and no signal that they could be shared.
Two concrete suggestions if you do bundle it:
Make the recorded-response path part of the contract, not an implementation detail. If responses bundles a snapshot feature, the file location and naming should be specified and documented, because people will commit those files and write assertions against them. A layout that accidentally collides across tests or silently merges two calls into one is much worse than an obvious "these two calls hit the same key, second one replaced the first."
Survive record="new_episodes". That mode is per-request, not per-session. A snapshot written under mixed mode contains both recorded and pre-registered responses, and on the next run they all come back as replayed. Anything that needs to know which is which later — freshness checks, "is this actually pinned by a test" assertions — breaks silently at exactly that boundary.
Your mocked_responses fixture and the update/playback branch is the right shape. If you want a second pair of eyes on the naming scheme or want a test case for the new_episodes interaction, happy to help.
Activity
nschloe commentedon Mar 28, 2025
This
might produce a filename which is too long. A better alternative is perhaps to hash the
request.node.nodeidand use that as a file stem.sswivell commentedon Oct 1, 2026
Disclosure: I maintain MockRelay, a different record/replay tool. Not trying to redirect the work here — your plugin is the right shape for a single-process library. One design question that cost me real time building the other thing, in case it's useful for the bundled plugin.
The hard part of "save responses to a file" isn't the saving, it's the identity.
In MockRelay a fixture's ID is derived from the request that produced it — upstream, method, path, query, and a hash of the redacted body. The consequence: recording the same endpoint twice with different responses overwrites one file. There is no ambiguity, it is deterministic, and it silently loses the second response.
That's the right default for a recorder whose job is "keep the fixture set current," and it's probably the wrong default for your plugin. In your snippet the filename is
f"{f}.yaml"wherefisrequest.node.name— so you're keying on the test node, which sidesteps the problem entirely by giving one snapshot per test. That's deliberate and good, but it means two tests hitting the same endpoint with different expected responses each get their own file, and you're never merging them. Whether that's a feature depends on what people are trying to fix with the plugin.The trade-off in your favour is that per-test keying means no collision is even possible, and re-recording is always a straight overwrite. The risk is that a user with a shared helper called from three tests gets three near-duplicate snapshots and no signal that they could be shared.
Two concrete suggestions if you do bundle it:
Make the recorded-response path part of the contract, not an implementation detail. If
responsesbundles a snapshot feature, the file location and naming should be specified and documented, because people will commit those files and write assertions against them. A layout that accidentally collides across tests or silently merges two calls into one is much worse than an obvious "these two calls hit the same key, second one replaced the first."Survive
record="new_episodes". That mode is per-request, not per-session. A snapshot written under mixed mode contains both recorded and pre-registered responses, and on the next run they all come back as replayed. Anything that needs to know which is which later — freshness checks, "is this actually pinned by a test" assertions — breaks silently at exactly that boundary.Your
mocked_responsesfixture and the update/playback branch is the right shape. If you want a second pair of eyes on the naming scheme or want a test case for thenew_episodesinteraction, happy to help.