kevin1024 / vcrpy

Automatically mock your HTTP interactions to simplify and speed up testing

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[5.0.0] No cassettes found? Worked with 4.x.x

Alexander-Serov opened this issue · comments

For some reason, after upgrading to vcrpy==5.0.0, the old cassettes on our working pipeline are not found anymore. Since there are no changes in code, something seems to have changed in vcrpy.

I understand it's a major version release, so it is the right place to introduce new functionality and break the old one, but in this case, I would like to suggest a clearer message to the user on how to fix it. For the moment, it just says that the cassettes are not found, which is wrong. They are present at the same location they are found by v4.*.

------------------------------ Captured log setup ------------------------------
INFO: <function VCR._build_before_record_request.<locals>.before_record_request at 0x7fa1fb8f5670>
_ ERROR at setup of file _
request = <SubRequest 'vcr' for <Function test_>>
vcr_markers = [Mark(name='vcr', args=(), kwargs={})]
vcr_cassette_dir = '/builds//tests/cassettes/test_fitting'
record_mode = 'none', disable_recording = False
pytestconfig = <_pytest.config.Config object at 0x7fa2225b41c0>
    @pytest.fixture(autouse=True)  # type: ignore
    def vcr(  # pylint: disable=too-many-arguments
        request: SubRequest,
        vcr_markers: List[Mark],
        vcr_cassette_dir: str,
        record_mode: str,
        disable_recording: bool,
        pytestconfig: Config,
    ) -> Iterator[Optional[Cassette]]:
        """Install a cassette if a test is marked with `pytest.mark.vcr`."""
        if disable_recording:
            yield None
        elif vcr_markers:
            config = request.getfixturevalue("vcr_config")
            default_cassette = request.getfixturevalue("default_cassette_name")
>           with use_cassette(
                default_cassette, vcr_cassette_dir, record_mode, vcr_markers, config, pytestconfig
            ) as cassette:
venv/lib/python3.8/site-packages/pytest_recording/plugin.py:150: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
venv/lib/python3.8/site-packages/vcr/cassette.py:89: in __enter__
    self.__cassette = self.cls.load(**cassette_kwargs)
venv/lib/python3.8/site-packages/vcr/cassette.py:177: in load
    new_cassette._load()
venv/lib/python3.8/site-packages/vcr/cassette.py:350: in _load
    requests, responses = self._persister.load_cassette(self._path, serializer=self._serializer)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
self = CombinedPersister(extra_paths=[])
cassette_path = '/builds//tests/cassettes/test_fitting/test_.yaml'
serializer = <module 'vcr.serializers.yamlserializer' from '/builds/venv/lib/python3.8/site-packages/vcr/serializers/yamlserializer.py'>
    def load_cassette(self, cassette_path: str, serializer: ModuleType) -> Tuple[List, List]:
        all_paths = chain.from_iterable(((cassette_path,), self.extra_paths))
        # Pairs of 2 lists per cassettes:
        all_content = (load_cassette(path, serializer) for path in unique(all_paths))
        # Two iterators from all pairs from above: all requests, all responses
        # Notes.
        # 1. It is possible to do it with accumulators, for loops and `extend` calls,
        #    but the functional approach is faster
        # 2. It could be done more efficient, but the `deserialize` implementation should be adjusted as well
        #    But it is a private API, which could be changed.
        requests, responses = starmap(unpack, zip(*all_content))
        requests, responses = list(requests), list(responses)
        if not requests or not responses:
>           raise ValueError("No cassettes found.")
E           ValueError: No cassettes found.
venv/lib/python3.8/site-packages/pytest_recording/_vcr.py:48: ValueError

@Alexander-Serov from a quick look it seems like:

What do you think?

@Alexander-Serov
PS: If you could report this as a bug to pytest-recording at https://github.com/kiwicom/pytest-recording/issues that would be great.
PPS: We also released VCR.py 4.4.0 yesterday, the planned last on the 4.x.x track. Downgrading to 4.4.0 is not a good long-term approach, but may help to put out the fire for the moment.

Hey @hartwork,

Thanks for the fast answer. Yes, this totally makes sense to me and you guessed it right, I am using vcrpy through pytest-recording. It didn't show up in the main error message, so I came here first, but yes, totally makes sense to file an issue on their side. Do you mind keeping this issue open here for the moment, in case it requires any interaction between the 2 issues (or as a landing zone for newcomers)?

And yes, we have temporarily downgraded on our side, but it should be properly fixed by pytest-recording, I agree! Thanks for the suggestion!

@Alexander-Serov thanks for the update. I have labelled the issue as a question now. We can link to this issue open or closed, I can try if pinning it for a few days works even in closed state, will see.

I think we still need to agree on who does the reporting to pytest-recording. Could you take that over? You need the change in pytest-recording more than I do, since I use plain VCR.py myself.

@Alexander-Serov PS: Pinning in close state seems to work fine:
pinning

@hartwork Great, thanks for the fast reaction!

// Suggested Solution:
// 1. Check the release notes and changelog for version 5.0.0 to identify any relevant changes related to cassette management or configuration.
// 2. Review the project's test and configuration files to ensure they align with the changes introduced in version 5.0.0.
// 3. If necessary, adjust the cassette setup or configuration to address the "No cassettes found" issue.
// Note: This issue might be specific to certain configurations or edge cases, so thorough testing and investigation are required to determine the root cause.