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.
[![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 details)
Built Distribution
File details
Details for the file pytest-vcr-0.2.0.tar.gz
.
File metadata
- Download URL: pytest-vcr-0.2.0.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 766e5cb5fa7d3184edc0c156f38ff21cf024b20a1e9de5f9330ec5bfc0548796 |
|
MD5 | 6bad93daa7d47c3e8ad0684414a87720 |
|
BLAKE2b-256 | b14383fa97419189dc071f5a6dd58266f3144fb35a8072975c00ae276094742c |
File details
Details for the file pytest_vcr-0.2.0-py2.py3-none-any.whl
.
File metadata
- Download URL: pytest_vcr-0.2.0-py2.py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 73957a057f89d7694b4f4bd2a3445058b23c86df3c1dd7c033c5713be852ded4 |
|
MD5 | 619f1924dfc7d13fd6e84b8d8779198c |
|
BLAKE2b-256 | b079b64d8882785af68e81060ae2bfeb6be69ec09ac711d05bb142fff18381f5 |