Skip to main content

No project description provided

Project description

expecttest PyPI version

This library implements expect tests (also known as "golden" tests). Expect tests are a method of writing tests where instead of hard-coding the expected output of a test, you run the test to get the output, and the test framework automatically populates the expected output. If the output of the test changes, you can rerun the test with the environment variable EXPECTTEST_ACCEPT=1 to automatically update the expected output.

Somewhat unusually, this library implements inline expect tests: that is to say, the expected output isn't saved to an external file, it is saved directly in the Python file (and we modify your Python file when updating the expect test.)

The general recipe for how to use this is as follows:

  1. Write your test and use assertExpectedInline() instead of a normal assertEqual. Leave the expected argument blank with an empty string:

    self.assertExpectedInline(some_func(), "")
    
  2. Run your test. It should fail, and you get an error message about accepting the output with EXPECTTEST_ACCEPT=1

  3. Rerun the test with EXPECTTEST_ACCEPT=1. Now the previously blank string literal will contain the expected value of the test.

    self.assertExpectedInline(some_func(), "my_value")
    

Some tips and tricks:

  • Often, you will want to expect test on a multiline string. This framework understands triple-quoted strings, so you can just write """my_value""" and it will turn into triple-quoted strings.

  • Take some time thinking about how exactly you want to design the output format of the expect test. It is often profitable to design an output representation specifically for expect tests.

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

expecttest-0.1.5.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

expecttest-0.1.5-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file expecttest-0.1.5.tar.gz.

File metadata

  • Download URL: expecttest-0.1.5.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.8.11 Darwin/22.5.0

File hashes

Hashes for expecttest-0.1.5.tar.gz
Algorithm Hash digest
SHA256 5b3a6a165250860f5a14199f9c59461752beb3b45d48b93347d9afc7293a611c
MD5 fac656e2d9bb9ddf9f6826ae2979918c
BLAKE2b-256 f24bcb8d0009c3496a410bebe70c4c1a5aba1dd10428ee887d5d169282061932

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: expecttest-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.8.11 Darwin/22.5.0

File hashes

Hashes for expecttest-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 cf051b6f4afa6107ccf8ad650e2aa3f6342665bc5adcd584856f2cf7007db305
MD5 8fe8274deb72c8b2244085919e9f990c
BLAKE2b-256 a56fb3bb854f697fb84990918ac72ccd6eec65101f78b1c148616ee3e10be6a3

See more details on using hashes here.

Provenance

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