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.2.tar.gz (96.7 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.2-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: snaptol-0.0.2.tar.gz
  • Upload date:
  • Size: 96.7 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.2.tar.gz
Algorithm Hash digest
SHA256 50b1a3ac95e1162d063f34639688360a52f439fd1bbf0f6b46ad6ec14da96a6c
MD5 1625ccf733edba8e353079af86dac1f6
BLAKE2b-256 9487177dd9fbf9e7d8ebd1150e96eb42a58241192e042b7ecb2d77979ca61f54

See more details on using hashes here.

Provenance

The following attestation bundles were made for snaptol-0.0.2.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.2-py3-none-any.whl.

File metadata

  • Download URL: snaptol-0.0.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d224c2de79762f3294d0e9640545d8746103c10aa706a3e217c9eb19524f498c
MD5 d9ede7db912c7bdb635ef58fd64e204a
BLAKE2b-256 9006997de573f5b17763729943fe793f6dff74ecca6e0f644256b7d20175cee2

See more details on using hashes here.

Provenance

The following attestation bundles were made for snaptol-0.0.2-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