vcrpy icon indicating copy to clipboard operation
vcrpy copied to clipboard

`CannotOverwriteExistingCassetteException` when no cassette exists is confusing

Open The-Compiler opened this issue 1 year ago • 3 comments

A trivial example such as:

import os.path
import urllib.request

import vcr

assert not os.path.exists("doesnotexist.yml")
with vcr.use_cassette("doesnotexist.yml", record_mode="none"):
    urllib.request.urlopen('http://www.iana.org/domains/reserved')

results in:

Traceback (most recent call last):
  [...]
  File "[...]/site-packages/vcr/stubs/__init__.py", line 263, in getresponse
    raise CannotOverwriteExistingCassetteException(
vcr.errors.CannotOverwriteExistingCassetteException: Can't overwrite existing cassette ('doesnotexist.yml') in your current record mode ('none').
No match for the request (<Request (GET) http://www.iana.org/domains/reserved>) was found.
No similar requests, that have not been played, found.

which seems confusing to me: The code failed because no cassette was found, yet the exception name and text claim "Can't override existing cassette".

The-Compiler avatar May 11 '24 16:05 The-Compiler

Have this been resolved? I encountered the same behavior

moustafasallam avatar May 23 '25 03:05 moustafasallam

You're answering your own question there, no? :wink:

The-Compiler avatar May 23 '25 12:05 The-Compiler

We recently switched to pytest-recording, which has record_mode="none" by default:

https://github.com/kiwicom/pytest-recording#default-recording-mode

I was surprised by this error message. But yeah, it seems to happen when record_mode="none" and no cassette exists.

IllyaMoskvin avatar Sep 19 '25 18:09 IllyaMoskvin