Skip to main content

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.

Project description

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.

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_lock-1.0.1.tar.gz (13.9 kB view details)

Uploaded Source

Built Distribution

pytest_lock-1.0.1-py3-none-any.whl (20.4 kB view details)

Uploaded Python 3

File details

Details for the file pytest_lock-1.0.1.tar.gz.

File metadata

  • Download URL: pytest_lock-1.0.1.tar.gz
  • Upload date:
  • Size: 13.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.10.12 Linux/6.2.0-1019-azure

File hashes

Hashes for pytest_lock-1.0.1.tar.gz
Algorithm Hash digest
SHA256 8f499a4b8f46202eeccaa789528c829a3efda0429a94d8c569d910d078e8e867
MD5 4f7ca70a9690e98d5f48645c9bd01916
BLAKE2b-256 eaecbb8bca2d62d1e3aee6b7a8d469958ff740aec72b16e8c915c1de7a107df9

See more details on using hashes here.

File details

Details for the file pytest_lock-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: pytest_lock-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 20.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.10.12 Linux/6.2.0-1019-azure

File hashes

Hashes for pytest_lock-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c73dcb563c4fee3d9b799434bd7f7f67dc6407627f67813ed6e0d4207c3d03f3
MD5 86618cf51c78d4cb3f4a801e237e72a1
BLAKE2b-256 7df42460ba60d060bb91f67c8ec3b27b5ae3643e82f9759ac0fe1e880d1a8856

See more details on using hashes here.

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