Skip to main content

No project description provided

Project description

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.

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

expect_def-0.0.3.tar.gz (2.6 MB view details)

Uploaded Source

Built Distribution

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

expect_def-0.0.3-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file expect_def-0.0.3.tar.gz.

File metadata

  • Download URL: expect_def-0.0.3.tar.gz
  • Upload date:
  • Size: 2.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.24.1

File hashes

Hashes for expect_def-0.0.3.tar.gz
Algorithm Hash digest
SHA256 1ff63394e10567b9f66554eb77cdfde0f7b8bed1d2de85894b4d66452647059a
MD5 f647b9ce67b5c3b6a4156a88b17377af
BLAKE2b-256 37eb16f7417c39f888b9102a94c2f248ee90e7f5cc3a373d858899131b93a5a0

See more details on using hashes here.

File details

Details for the file expect_def-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: expect_def-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.24.1

File hashes

Hashes for expect_def-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c0fe03ff2f9a72f2b85961691909aeb15466d9188cde97ee99093617cb099fa8
MD5 3bf1d076e84834c206c036e3fd7c1d17
BLAKE2b-256 45def4fd0c44f2cf2fd3c1ae26978237ba744ebd56f139e4a10c2c7b984ff18a

See more details on using hashes here.

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