ktosiek / pytest-vcr

Py.test integration with VCR.py
MIT License
150 stars 25 forks source link

Easy way to determine if running test with vcr disabled #33

Closed neozenith closed 4 years ago

neozenith commented 4 years ago

I am running a test like this:

@pytest.mark.vcr
def test_simple(vcr_cassette):
    # Given
    <insert test assumptions>

    # When
    <insert actual test scenario>

    # Then
    assert vcr_cassette.all_played
    assert vcr_cassette.play_count == 8

When I run my tests with VCR disabled the play_count is 0..... Understandably.

I'd like to change this to:

if not vcr_disabled:
    assert vcr_cassette.play_count == 8

But it seems that the pytest-vcr marker doesn't have an obvious way to check if the lambda was set to None.

https://github.com/ktosiek/pytest-vcr/blob/4fb277ee37b8b89d0fe7139bc79597db32f024fd/pytest_vcr.py#L59

I'll have a crack at a PR later that exposes on the _vcr_marker fixture a boolean property that can get assigned at that point in the code I linked but defaults to False unless it hits that code path.

neozenith commented 4 years ago

So this turned out to be way beyond my skillset to make the modification and update the tests.