Skip to main content

Python unittest integration for vcr.py

Project description

Build Status Coverage Report PyPI Gitter

This package provides VCRTestCase for simple integration between VCR.py and Python’s venerable unittest.

Installation

Install from PyPI:

pip install vcrpy-unittest

Usage

Inherit from VCRTestCase for automatic recording and playback of HTTP interactions.

from vcr_unittest import VCRTestCase
import requests

class MyTestCase(VCRTestCase):
    def test_something(self):
        response = requests.get('http://example.com')

Similar to how VCR.py returns the cassette from the context manager, VCRTestCase makes the cassette available as self.cassette:

self.assertEqual(len(self.cassette), 1)
self.assertEqual(self.cassette.requests[0].uri, 'http://example.com')

By default cassettes will be placed in the cassettes subdirectory next to the test, named according to the test class and method. For example, the above test would read from and write to cassettes/MyTestCase.test_something.yaml

The configuration can be modified by overriding methods on your subclass: _get_vcr_kwargs, _get_cassette_library_dir and _get_cassette_name. See the source for the default implementations, and VCR.py for more information.

Compatibility

VCRTestCase supports a subset of the Python versions supported by VCR.py. Specifically Python 2.6 is excluded, because it lacks TestCase.addCleanup. Adding support for Python 2.6 would be pretty easy with tearDown but that implementation is fragile because it depends on nothing else going wrong in the inheritance chain. Rather than take on this additional complexity, Python 2.6 is simply excluded for now.

License

This library uses the MIT license, which is the same as VCR.py. See LICENSE.txt for more details.

Acknowledgements

Thanks to @kevin1024 for VCR.py, and to @IvanMalison for his constructive critique on this package. Also thanks to @nedbat for his post regarding unittest and context managers, and to @davepeck for httreplay which served me well for so long.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vcrpy-unittest-0.1.4.tar.gz (3.5 kB view details)

Uploaded Source

File details

Details for the file vcrpy-unittest-0.1.4.tar.gz.

File metadata

File hashes

Hashes for vcrpy-unittest-0.1.4.tar.gz
Algorithm Hash digest
SHA256 2a81a00f6aefb96698f34a734151dd82294c544e91c6be63de926fb461e1eebb
MD5 13f4322a8b34aacccd6000f988486323
BLAKE2b-256 81f9e8b17f2d08035343c1e9e4006978ad0413b3de29b5ef6e2f1f15594764e8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page