Skip to main content

Plugin for managing VCR.py cassettes

Project description

# Welcome to pytest-vcr

[![Travis (Linux) test status](https://travis-ci.org/ktosiek/pytest-vcr.svg?branch=master)](https://travis-ci.org/ktosiek/pytest-vcr)
[![AppVeyor (Windows) test status](https://ci.appveyor.com/api/projects/status/github/ktosiek/pytest-vcr?branch=master)](https://ci.appveyor.com/project/ktosiek/pytest-vcr/branch/master)
[![Documentation Status](https://readthedocs.org/projects/pytest-vcr/badge/?version=latest)](http://pytest-vcr.readthedocs.io/en/latest/?badge=latest)


Py.test plugin for managing [VCR.py](https://vcrpy.readthedocs.io/) cassettes.


# Quick Start

Install the plugin with:

```sh
pip install pytest-vcr
```

Annotate your tests:

```python
@pytest.mark.vcr()
def test_iana():
response = urlopen('http://www.iana.org/domains/reserved').read()
assert b'Example domains' in response
```

And that's it!
A new file `cassettes/test_iana.yaml` will be created next to your test file on the first run.
This file should be committed to a VCS.


# Example configuration

## Filtering saved request/response
VCR.py registers full request and response, including headers, which often include passwords or API keys.
It's important to make sure you aren't leaving any secrets in your cassettes.
For example, when using HTTP Basic authentication, you should add this to your conftest:

```python
@pytest.fixture
def vcr_config():
return {
# Replace the Authorization request header with "DUMMY" in cassettes
filter_headers=[('authorization', 'DUMMY')],
}
```

For a way to specify separate configuration for different tests see [Configuration](configuration.md).


## Changing the cassettes library path
By default pytest-vcr will put cassettes in a `cassettes` directory next to your tests.
You can change that by overriding the `vcr_cassette_path` fixture:

```python
@pytest.fixture
def vcr_cassette_path(request, vcr_cassette_name):
# Put all cassettes in vhs/{module}/{test}.yaml
return os.path.join('vhs', request.module.__name__, vcr_cassette_name)
```


# Running on CI
When running your tests on CI it's recommended to use the `--vcr-record-mode=none` option.
This way you can make sure that you have committed all the cassettes.


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

pytest-vcr-0.2.0.tar.gz (3.9 kB view hashes)

Uploaded Source

Built Distribution

pytest_vcr-0.2.0-py2.py3-none-any.whl (5.4 kB view hashes)

Uploaded Python 2 Python 3

Supported by

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