No project description provided
Project description
expecttest
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:
-
Write your test and use
assertExpectedInline()
instead of a normalassertEqual
. Leave the expected argument blank with an empty string:self.assertExpectedInline(some_func(), "")
-
Run your test. It should fail, and you get an error message about accepting the output with
EXPECTTEST_ACCEPT=1
-
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file expecttest-0.2.1.tar.gz
.
File metadata
- Download URL: expecttest-0.2.1.tar.gz
- Upload date:
- Size: 6.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.8.11 Darwin/23.1.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e52b1cf8a6f84506e6962a0bbdd248ea442124d826e849f263ec1c322ebb73f5 |
|
MD5 | e579d563c28eacd508d8a9814b51ea5a |
|
BLAKE2b-256 | 49f1ce746b7508496340f780a9ba7c3b0eb8bf5ab4826dabcd86166e5fcd9ff8 |
File details
Details for the file expecttest-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: expecttest-0.2.1-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.8.11 Darwin/23.1.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 36f07b2f2800c12e5a0a5763d420f9f9b91631329bd54537509ebf17f8f81c36 |
|
MD5 | 3ffd16d3aca06436f66727aaa3fcdac2 |
|
BLAKE2b-256 | 73a89427813686fe043eaf817b99444d4d321ce14f9434e3ffb6bbd1a182a8df |