vcrpy-unittest
raw JSON → 0.1.7 verified Mon Apr 27 auth: no python
Provides a decorator `@use_cassette` for integrating vcr.py into Python's unittest framework. Current version 0.1.7, updated infrequently.
pip install vcrpy-unittest Common errors
error ImportError: cannot import name 'use_cassette' from 'vcrpy_unittest' ↓
cause Using hyphenated package name instead of underscored one.
fix
Use
from vcr_unittest import use_cassette. error AttributeError: module 'vcr_unittest' has no attribute 'use_cassette' ↓
cause Maybe older version or wrong import; check vcr_unittest is installed and import correctly.
fix
pip install vcrpy-unittest and then import from vcr_unittest import use_cassette. Warnings
gotcha The cassette file path is relative to the working directory, not the test file. Use an absolute path or ensure correct working directory. ↓
fix Use `@use_cassette(os.path.join(os.path.dirname(__file__), 'fixtures/cassettes/test.yaml'))`
gotcha The decorator only works on instance methods of unittest.TestCase subclasses. It will break on standalone functions or other test runners (pytest). ↓
fix Ensure decorated method belongs to a unittest.TestCase class.
Imports
- use_cassette wrong
from vcrpy_unittest import use_cassettecorrectfrom vcr_unittest import use_cassette
Quickstart
import unittest
from vcr_unittest import use_cassette
class TestMyAPI(unittest.TestCase):
@use_cassette('fixtures/cassettes/test_request.yaml')
def test_request(self):
import requests
resp = requests.get('http://httpbin.org/get')
self.assertEqual(resp.status_code, 200)