Code examples for my talk, Property-based testing with Hypothesis, at the PyBCN Meetup on 2021-11-25.
Property-based testing is introduced and discussed in the context of Test-Driven Development, and Hypothesis is introduced as one of the leading packages for property-based testing in python.
Then we discuss an exercise about writing a program using TDD and testing it using Hypothesis. The code for that exercise is contained here.
You will need to install both hypothesis and pytest. I originally wrote the code in Python 3.9, but I reckon anything newer than 3.6 should most probably work (lemme know by opening an issue if that is the case).
pip install pytest hypothesis
pytest -v
If you use poetry, I have provided my pyproject.toml
and poetry.lock
. On an environment with Python 3.9:
poetry install
pytest -v