PyTest Process VCR
Project description
pytest-pvcr
A pytest plugin that records and replays commands executed with subprocess.run().
This plugin was inspired by VCR.py.
Installation
This project can be installed via pip:
pip install pytest-pvcr
Usage
import subprocess
import pytest
@pytest.mark.pvcr()
def test_command():
# subprocess.run is patched at runtime
ret = subprocess.run(["ls", "/tmp"])
assert rc.returncode == 0
@pytest.mark.pvcr(wait=False)
def test_command():
# Super long command but since wait == False, PVCR does not wait its completion
ret = subprocess.run(["sleep", "1000"])
assert rc.returncode == 0
Run your tests:
pytest --pvcr-record-mode=new test_commands.py
Record modes
There is three record modes:
# Only record new commands not previously recorded
pytest --pvcr-record-mode=new test_commands.py
# Record nothing
pytest --pvcr-record-mode=none test_commands.py
# Record all commands, even previously recorded ones
pytest --pvcr-record-mode=all test_commands.py
Block execution
The execution of processes can be completely blocked. This is useful to protect test environments from destructive commands.
pytest --pvcr-block-run test_commands.py
The test will fail if an unrecorded command is executed.
Fuzzy matching
Commands can be fuzzy matched by defining one or more regex.
If a fuzzy regex has matching groups, the matched parts are kept for matching the commands.
If a fuzzy regex has no matching groups, the whole matched string is ignored when matching the commands.
# Ignore `--dry-run` arguments when matching commands
pytest --pvcr-fuzzy-matcher='--dry-run' test_commands.py
# Ignore the beginning of a path and keep the filename
pytest --pvcr-fuzzy-matcher='^.+\/(kubeconfig)$' test_commands.py
It's possible to automatically ignore the parent path of the test script. This parameter is useful to make test assets portable.
pytest --pvcr-auto-fuzzy-match test_commands.py
Python support
This plugin supports python >= 3.12
Authors
- Fabien Dupont fab+github@kafe-in.net
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytest_pvcr-0.1.2.tar.gz.
File metadata
- Download URL: pytest_pvcr-0.1.2.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7db99933bb91e1d3c6317fa0eb91822a4c06a55e3784d09e5ecfe00b4525720
|
|
| MD5 |
8d646f9ef15c8e8b42a18d3c3427b0bd
|
|
| BLAKE2b-256 |
8c0765e73668580adf95dae53c54773d611efe98ffe641028ead02d44264af4b
|
Provenance
The following attestation bundles were made for pytest_pvcr-0.1.2.tar.gz:
Publisher:
publish-to-pypi.yml on kafeinnet/pytest-pvcr
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytest_pvcr-0.1.2.tar.gz -
Subject digest:
b7db99933bb91e1d3c6317fa0eb91822a4c06a55e3784d09e5ecfe00b4525720 - Sigstore transparency entry: 991508654
- Sigstore integration time:
-
Permalink:
kafeinnet/pytest-pvcr@7dc08c2e5aa30a555906623b7005024d036f8abd -
Branch / Tag:
refs/tags/0.1.2 - Owner: https://github.com/kafeinnet
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@7dc08c2e5aa30a555906623b7005024d036f8abd -
Trigger Event:
push
-
Statement type:
File details
Details for the file pytest_pvcr-0.1.2-py3-none-any.whl.
File metadata
- Download URL: pytest_pvcr-0.1.2-py3-none-any.whl
- Upload date:
- Size: 8.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a9983369d6f442defd63d9c7224ae1a0142bf41cd68766fdb9b6a9541387e7f8
|
|
| MD5 |
d0cb2f801a0342d9dec1f3b1a33d926b
|
|
| BLAKE2b-256 |
6d6e3983d0ad12bef47de022bf12a2c93e5a1d8c361a3de17badf509d0ac362d
|
Provenance
The following attestation bundles were made for pytest_pvcr-0.1.2-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on kafeinnet/pytest-pvcr
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytest_pvcr-0.1.2-py3-none-any.whl -
Subject digest:
a9983369d6f442defd63d9c7224ae1a0142bf41cd68766fdb9b6a9541387e7f8 - Sigstore transparency entry: 991508657
- Sigstore integration time:
-
Permalink:
kafeinnet/pytest-pvcr@7dc08c2e5aa30a555906623b7005024d036f8abd -
Branch / Tag:
refs/tags/0.1.2 - Owner: https://github.com/kafeinnet
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@7dc08c2e5aa30a555906623b7005024d036f8abd -
Trigger Event:
push
-
Statement type: