Skip to main content

pytest-vcr-delete-on-fail

PyPI PyPI - Python Version CI Status Coverage status Sonarqube ratings: A License: GPL-3.0 Maintained! Code style: black

A pytest plugin that automates vcrpy cassettes deletion on test failure.

$ pip install pytest-vcr-delete-on-fail

Then, in your test:

import pytest
import requests
import vcr

my_vcr = vcr.VCR(record_mode="once")

cassette_path = "tests/cassettes/this.yaml"

@pytest.mark.vcr_delete_on_fail(cassette_path)
def test_this():
    with my_vcr.use_cassette(cassette_path):
        requests.get("https://github.com")
    assert False

In this example a cassette will be saved on disk when exiting the use_cassette context manager, but since the test eventually fails, the cassette will be deleted after the test teardown.

Rationale

Sometimes when testing a function containing multiple http requests a failure will occur halfway through (this happens all the time when doing TDD). When using vcrpy to cache http requests, this could result in a test cache that only cover a fraction of the function under test, which in turn could prevent the function to ever succeed or the test to pass in subsequent run if the http requests that didn’t get cached depended on a fresh context (maybe they are time sensitive or there’s randomness involved).

This possibility leads to doubt and lack of trust towards the test suite, which is wrong on too many level.

This plugin provides tools to solve this uncertainty, by deleting a test http requests cache if it fails, so that it can start fresh on the next run.

Docs

More information and examples can be found in the in-depth documentation.

Development

Install invoke and poetry:

$ pip install invoke poetry

Now clone the git repo:

$ git clone https://github.com/CarloDePieri/pytest-vcr-delete-on-fail.git
$ cd pytest-vcr-delete-on-fail
$ inv install

This will try to create a virtualenv based on python3.8 and install there all project’s dependencies. If a different python version is preferred, it can be selected by specifying the --python (-p) flag like this:

$ inv install -p python3.9

The test suite can be run with commands:

$ inv test         # run the test suite
$ inv test-cov     # run the tests suite and produce a coverage report

To run the test suite against all supported python version (they must be in path!) run:

$ inv test-all-python-version

To test the GitHub workflow with act:

$ inv act-dev               # test the dev workflow
$ inv act-dev -c shell      # open a shell in the act container (the above must fail first!)
$ inv act-dev -c clean      # stop and delete a failed act container

To write the documentation with autobuild and livereload launch:

$ inv docs-serve

Metadata

Release files for pytest-vcr-delete-on-fail 2.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-vcr-delete-on-fail 2.0.1
File Size Uploaded Provenance
pytest_vcr_delete_on_fail-2.0.1.tar.gz 18.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-vcr-delete-on-fail 2.0.1
File Interpreter ABI Platform
pytest_vcr_delete_on_fail-2.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 37.7 kB

Release files / pytest_vcr_delete_on_fail-2.0.1.tar.gz

Download URL pytest_vcr_delete_on_fail-2.0.1.tar.gz
Size 18.4 kB
Tags Source
SHA-256 checksum
How to use checksums
7f07e079615cfdcda01e8d24367b6b2a89402e094e1f7439ff3ac35b59807200
BLAKE2b-256 checksum
How to use checksums
9bd15e17a60fa534a5480fddd3faee8a4102a4af574c3a3514db1927b1539497
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.8.18 Linux/6.2.0-1019-azure

Release files / pytest_vcr_delete_on_fail-2.0.1-py3-none-any.whl

Download URL pytest_vcr_delete_on_fail-2.0.1-py3-none-any.whl
Size 19.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fe4fbd0067da3d7f33b24e169344c03bfdf0001a604ece8a55b1b794e92a410b
BLAKE2b-256 checksum
How to use checksums
37271939dc65709919e4d7dd86a19d07b4d43cb34af13fd1470b263460179c52
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.8.18 Linux/6.2.0-1019-azure

Security for pytest-vcr-delete-on-fail 2.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page