kevin1024 / vcrpy

Automatically mock your HTTP interactions to simplify and speed up testing
MIT License
2.65k stars 377 forks source link

Request: RecordMode to force-overwrite the cassette #578

Open JayBazuzi opened 3 years ago

JayBazuzi commented 3 years ago

From the README:

If the server you are testing against ever changes its API, all you need to do is delete your existing cassette files, and run your tests again.

I want this behavior as a configuration parameter to VCR: I want to set a RecordMode that will replace the existing cassette with fresh new data.

One way this would be useful is when I'm iterating on a filter:

  1. Run the test
  2. Examine the cassette, looking for a secret that has been captured
  3. Modify a filter to redact that secret
  4. Run the test again

Today this is only possible if I add:

3.5. Delete the correct cassette file

Originally I thought this is what RecordMode.ALL might do, but was disappointed to find that it only appends not overwrites. I considered suggesting that ALL should in fact delete the existing recorded requests, but maybe that's a breaking change that you don't want.

MaxenceG2M commented 2 years ago

Hi,

I share this issue.

But I have some interrogation with the "ALL" mode

This can be temporarily used to force VCR to re-record a cassette (i.e. to ensure the responses are not out of date) For me, this means that old records should be overwritten by new records. This is not currently the behavior.

But :

can be used when you simply want to log all HTTP requests means all requests should be recorded...

So I don't know if a good move will be to edit "ALL" mode to erase old record, and append new one. Or add a mode to "rewrite" and juste keep last query.

MartinFalatic commented 2 years ago

This would be particularly useful for Dockerized tests that interact with the local filesystem.

If your container contains some cassette mytest.yml, and you want to completely rewrite it, 'all' won't do the job - it'll append, and you'll end up having to manually trim out the old data.

If you remove the file (locally) and run the test... surprise! Docker shadowed it so you get an appended file again (vexing when you're trying to understand why it's not updating correctly).

A 'replace' mode should entirely ignore the existing cassette and write an entirely new one to the cassette file, eliminating these problems.