kiwicom / pytest-recording

A pytest plugin that allows recording network interactions via VCR.py
MIT License
425 stars 34 forks source link

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

Closed paxcodes closed 3 years ago

paxcodes commented 3 years ago

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):

Stranger6667 commented 3 years ago

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.

Stranger6667 commented 3 years ago

The docs are updated

arthurio commented 3 years ago

@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?

Stranger6667 commented 3 years ago

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