Skip to main content

expect-def

PyPI - Version PyPI - Python Version


Motivation

Expect tests give you a repl-like interactive development experience where any manual tests you make are trivially turned into automated assertions. The process of changing these assertions to match new constraints is as easy as can be.

See Jane Street's blog post The Joy of Expect Tests.

Usage

Create a test like so:

import expect_def as expect

@expect.test
def test_five_times_five():
    print(5 * 5)

This can be in a file specifically for testing or right next to the code it is testing. Anything you print will become an assertion

To run it, create a test.py file in the root of your project:

import src.your_project_here
import expect_def
expect_def.run

Make sure to import any modules whose tests you would like to run.

Runing python test.py test will show you a diff of the expected output if the tests fails:

/Users/charles/code/python-expect-def/example/__init__.py failed
------ /Users/charles/code/python-expect-def/example/__init__.py
++++++ /Users/charles/code/python-expect-def/example/__init__.py.err
@|-2,4 +2,7 ============================================================
 |
 |@expect.test
 |def test_five_times_five():
+|    """
+|    25
+|    """
 |    print(5 * 5)

Which you can accept with python test.py accept.

Alternatives

See also snapshottest and expecttest and pytest-expect. These don't make use of doc strings as the assertion mechanism and some integrate with pytest.

Installation

pip install expect-def

expect-def also depends on patdiff to show diffs, make sure to have that on the PATH.

License

expect-def is distributed under the terms of the MIT license.

Metadata

Release files for expect-def 0.0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for expect-def 0.0.7
File Size Uploaded Provenance Actions
expect_def-0.0.7.tar.gz 3.3 MB Without provenance Details for expect_def-0.0.7.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for expect-def 0.0.7
File Interpreter ABI Platform Actions
expect_def-0.0.7-py3-none-any.whl Python 3 none any Details for expect_def-0.0.7-py3-none-any.whl

Total release size: 3.3 MB

Release files / expect_def-0.0.7.tar.gz

Download URL expect_def-0.0.7.tar.gz
Size 3.3 MB
Tags Source
SHA-256 checksum
How to use checksums
5a70f46c1478354e0e9a7eeea993b32e31cec5cee0f0b3ec33d88b310f5c1296
BLAKE2b-256 checksum
How to use checksums
f01e297ee1ad3b346c77ce35e399ce459a5b45d644f245bf627a50ab1b650ee0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.24.1

Release files / expect_def-0.0.7-py3-none-any.whl

Download URL expect_def-0.0.7-py3-none-any.whl
Size 4.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c5d409a26fcae93098ffe38225b7612756bd322b9091f552320c0ef29d76b83c
BLAKE2b-256 checksum
How to use checksums
cca63ac90f18153c9fc3c6dc13c84aa5544fbfd5d846ad58833ffe4992fa8c8f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.24.1

Security for expect-def 0.0.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page