Skip to main content

pytest-lock

Overview

License MIT Python versions PyPI version codecov Workflow Documentation Status Security: Bandit

pytest-lock is a pytest plugin that allows you to "lock" the results of unit tests, storing them in a local cache. This is particularly useful for tests that are resource-intensive or don't need to be run every time. When the tests are run subsequently. pytest-lock will compare the current results with the locked results and issue a warning if there are any discrepancies.

Installation

To install pytest-lock, you can use pip:

pip install pytest-lock

Usage

Locking Tests

To lock a test, use the lock fixture. Here's an example:

from pytest_lock import FixtureLock


def test_lock_sum(lock: FixtureLock):
    args = [1, 2, 3]
    lock.lock(sum, (args,))
    ...

Run pytest with the --lock option to generate the lock files:

pytest --lock

This will generate JSON files in a .pytest-lock directory, storing the results of the locked tests.

Running Tests

Simply run pytest as you normally would:

pytest

If pytest detect the presence of lock fixtures in your tests, it will compare the results of the tests with the locked If a test result differs from its locked value, a warning will be issued.

Configuration

The locked test results are stored in a .pytest-lock directory at the root of your project. You can delete this directory to reset all locks.

Contributing

Contributions are welcome! Please read the contributing guidelines to get started.

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

Release files for pytest-lock 1.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-lock 1.0.1
File Size Uploaded
pytest_lock-1.0.1.tar.gz 13.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-lock 1.0.1
File Interpreter ABI Platform
pytest_lock-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 34.3 kB

Release files / pytest_lock-1.0.1.tar.gz

Download URL pytest_lock-1.0.1.tar.gz
Size 13.9 kB
Tags Source
SHA-256 checksum
How to use checksums
8f499a4b8f46202eeccaa789528c829a3efda0429a94d8c569d910d078e8e867
BLAKE2b-256 checksum
How to use checksums
eaecbb8bca2d62d1e3aee6b7a8d469958ff740aec72b16e8c915c1de7a107df9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.10.12 Linux/6.2.0-1019-azure

Release files / pytest_lock-1.0.1-py3-none-any.whl

Download URL pytest_lock-1.0.1-py3-none-any.whl
Size 20.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c73dcb563c4fee3d9b799434bd7f7f67dc6407627f67813ed6e0d4207c3d03f3
BLAKE2b-256 checksum
How to use checksums
7df42460ba60d060bb91f67c8ec3b27b5ae3643e82f9759ac0fe1e880d1a8856
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.10.12 Linux/6.2.0-1019-azure

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

2 release files

0.1.2

2 release files

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