kiwicom / pytest-recording

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

Custom VCR config via separate fixture #2

Closed Stranger6667 closed 5 years ago

Stranger6667 commented 5 years ago

Currently, there is no way to specify a module/session-level config without wrapping everything with pytest.mark.vcr. E.g. test module has 10 tests, 2 of them use pytest.mark.vcr - if they share the same config it will require manual explicit specification on each mark, which means some duplication. An alternative solution is to have a separate fixture of any scope - vcr_config that will be added to the VCR config implicitly (like it is in pytest-vcr).


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

@pytest.mark.vcr
def test_a():
    pass

@pytest.mark.vcr
def test_b():
    pass

def test_c():
    pass

In this case, we can avoid VCR setup where it is not needed and the vcr_config fixture could be the first in the merging process - all marks will override colliding keys