Skip to main content

Used to lock object during testing. Essentially changing assertions from being hard coded to asserting that nothing changed

Project description

actions batch pypi codecov

PyTest-Locker

The test-locker can be used to “lock” data from during a test. This means that rather than having to manually specify the expected output you lock the data when it corresponds to expected bahaviour.

Why use Locker

  • Time efficient: No need to hard code expected responses. (Especially usefull for data heavy unittests)

  • Easy to verify changes:

    • Seperates logic of the test and expected values in the test further

    • Lock files, and changes to them, are easy to interpret. Therefore, evaluting them in pull-requests a great method of quality controll.

install

run pip install pytest-locker

Use

  • Step 1: Add from pytest_locker import locker to your conftest.py file

  • Step 2: To access the locker by adding it to the method parameters i.e. def test_example(locker)

  • Step 3: Use locker.lock(your_string, optional_name) to lock the data.

  • Additionally: Don’t forget to commit the .pytest_locker/ directory for ci/cd testing

And you’re all set!

The Locker test Flows

There are two modes based on for locking.

  • When user input is allowed, i.e. when running pytest with --capture no

    When user input is allowed and the given data does not correspond to the data in the lock the user is prompted if the new data should be stored or if the tests should fail.

  • When user input is captured which is default behavior for pytest

    If user input is not allowed the tests will automatically fail if the expected lock file does not exist or if the data does not correspond to the data in the lock file.

The Locker class

You can also use pytest_locker.Locker (i.e. the class of which the locker fixture returns an instance). directly to create fixtures that locks a (non-string) object without needing to turn the object into a string it.

Examples

For example of use look at the tests in https://github.com/Luttik/repr_utils.

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-locker-0.1.5.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_locker-0.1.5-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file pytest-locker-0.1.5.tar.gz.

File metadata

  • Download URL: pytest-locker-0.1.5.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.5 CPython/3.8.2 Windows/10

File hashes

Hashes for pytest-locker-0.1.5.tar.gz
Algorithm Hash digest
SHA256 5ec6bec8d481221a3061866bd2d40f24a9ba3b245892a07b4284dcf3cc5af359
MD5 313033518dad44d3cd7808e484f78220
BLAKE2b-256 01e1df6e72814ee4d532a154606455c22cf67740ccfa7e781538ac16b374857b

See more details on using hashes here.

File details

Details for the file pytest_locker-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: pytest_locker-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 3.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.5 CPython/3.8.2 Windows/10

File hashes

Hashes for pytest_locker-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 e0802b768b1b9e2458fb6371f7685c27c02d84c8c8b8161cc6f1bc0bd296a744
MD5 4be0a7da4ffef412206cdafc4227a224
BLAKE2b-256 870da735ec6b06100a810ac538330627ab68a6ddeb702fcdcda94603d50f16d5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page