Accompanying repository for the RSECon24 talk "Advanced Python Testing - mocking, property based testing, snapshot testing"
Setup requires Python 3 (>=3.10)
git clone https://github.com/abhidg/advanced-python-testing && cd advanced-python-testing
python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install -r requirements.txt
To run the tests:
python3 -m pytest -v
You can also run test files individually:
python3 -m pytest tests/<file> -v
- Standard library has extensive documentation: https://docs.python.org/3/library/unittest.mock-examples.html
- Specialised libraries moto (AWS), requests-mock, freezegun (datetime mocking)
- Mocks can automatically match specs, see
autospec
- The
hypothesis
site has introductory articles: https://hypothesis.works/articles/getting-started-with-hypothesis/ - Extensions to
hypothesis
:schemathesis
for API testing,hypothesis-jsonschema
for generating JSON complying with a JSON Schema.