betamaxpy / betamax

A VCR imitation designed only for python-requests.
https://betamax.readthedocs.io/en/latest/
Other
565 stars 62 forks source link

Record mode 'new_episodes' broken #130

Closed yigor closed 6 years ago

yigor commented 7 years ago

I noticed that record mode new_episodes doesn't work as it used to and as I expect it to work. It records new interaction even if absolutely identical one already exists in the current cassette. Please take a look at following code:

import time
import pytest
from betamax import Betamax
from requests import Session

def test_new_episodes():
    url = 'https://github.com/sigmavirus24/betamax/'
    session = Session()
    cassette_name = 'test_new_episodes_{}'.format(time.time())
    recorder = Betamax(session, default_cassette_options={'record_mode': 'new_episodes'})
    with recorder.use_cassette(cassette_name):
        session.get(url)
    recorder = Betamax(session, default_cassette_options={'record_mode': 'new_episodes'})
    with recorder.use_cassette(cassette_name):
        session.get(url)
        assert len(recorder.current_cassette.interactions) == 1

This test passes with version 0.5.1 but fails with all the newer ones. I think because of this line matching interaction is never found and new one gets recorded.

sigmavirus24 commented 6 years ago

I noticed that record mode new_episodes doesn't work as it used to and as I expect it to work. It records new interaction even if absolutely identical one already exists in the current cassette.

Yes. This was implemented to conform to the behaviour of VCR. This tool hasn't yet had a stable (1.0) release yet so there may be some other minor incompatibilities in the future.

peterisr commented 3 years ago

Looks like this wasn't the intended behavior after all. It was changed in PR https://github.com/betamaxpy/betamax/pull/154, however there hasn't been a new betamax release since then.