Skip to main content

A Python tool for snapshot testing with numerical tolerance on floating point numbers

Project description

snaptol

A Python tool for snapshot testing with numerical tolerance on floating point numbers.

Installation

Use the package manager pip to install snaptol.

pip install snaptol

Usage

Normal usage

In a test file, add the snapshot fixture, snaptolshot,

def test_something(snaptolshot):
    result = compute_something()
    assert snaptolshot == result

When pytest runs, it will compare the result to the snapshot stored in file.

To provide a tolerance, pass it as an argument to the fixture,

def test_something(snaptolshot):
    result = compute_something()
    assert snaptolshot(rtol=1e-05, atol=1e-08) == result

Alternatively, use the match method,

def test_something(snaptolshot):
    result = compute_something()
    assert snaptolshot.match(rtol=1e-05, atol=1e-08) == result

Updating snapshots

On initial pass and subsequent changes to the test, run pytest with the --snapshot-update flag,

pytest --snapshot-update

This will not perform the comparison between snapshot and result, but rather update the snapshot file with the current result.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

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

snaptol-0.0.1.tar.gz (96.5 kB view details)

Uploaded Source

Built Distribution

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

snaptol-0.0.1-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file snaptol-0.0.1.tar.gz.

File metadata

  • Download URL: snaptol-0.0.1.tar.gz
  • Upload date:
  • Size: 96.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for snaptol-0.0.1.tar.gz
Algorithm Hash digest
SHA256 a84d3573766df886b5dfcf896a31eab3b528213d388343b590a0a03d1c041b18
MD5 947e176d563aba02d93dae149be7aa79
BLAKE2b-256 4b91ecd4f785db8c7b8c21e0373813b58af7d272c01b2f63e08c333d4b78eaa3

See more details on using hashes here.

Provenance

The following attestation bundles were made for snaptol-0.0.1.tar.gz:

Publisher: release.yml on PlasmaFAIR/snaptol

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file snaptol-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: snaptol-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for snaptol-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1f4f36a29f458df1ea279b2e60a4b53eb80516584cede2c936ae717d37fb42fd
MD5 71700b8622ec987f2cc14db5a76ab3b4
BLAKE2b-256 fc0054c84dcb75160de5596483d796ebb9150dc22aab9fccb8f072eaaa256bae

See more details on using hashes here.

Provenance

The following attestation bundles were made for snaptol-0.0.1-py3-none-any.whl:

Publisher: release.yml on PlasmaFAIR/snaptol

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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