kiwicom/pytest-recording

[BUG] Default record_mode is 'none' instead of 'once'

Closed this issue · 4 comments

Describe the bug
When I use the decorator without passing any record_mode (@pytest.mark.vcr), I get an error saying,

vcr.errors.CannotOverwriteExistingCassetteException: Can't overwrite existing cassette ('/path/test_single.yaml') in your current record mode ('none').

The VCR docs says the default mode is "once" and pytest-recording doesn't mention the default mode, implying it follows VCR's.

To Reproduce
Use the sample test in the docs,

@pytest.mark.vcr
def test_single():
    actualResponse = requests.get("https://httpbin.org/get")
    assert actualResponse.status_code == 200

Expected behaviour
No errors.

Environment (please complete the following information):

  • OS: MacOS
  • Python version: 3.8.7
  • pytest-recording version: 0.11.0
  • pytest version: 6.2.2

Thank you for pointing this out!

I completely missed mentioning it in the docs - this behavior is intentional to avoid network calls by default. It was a major problem at kiwi.com when I was working there, and therefore we choose a more conservative approach here. I'll update the docs soon.

The docs are updated

@Stranger6667 For my personal case I wanted to have once by default, so I set the config:

@pytest.fixture(scope="module")
def vcr_config():
    return {
        "record_mode": "once",
   }

Unfortunately, when you do that, passing options to pytest doesn't overwrite it... e.g. pytest --record-mode=rewrite would still execute with once. Should I open another issue for that or is there another trick I don't know about?

@arthurio
Yes, please, open a separate issue for it