Advanced Python Testing - mocking, property based testing, snapshot testing
In this walkthrough, take your Python testing skills to the next level. Tired of waiting for network requests, writing millions of edge cases and copy pasting outputs for testing? This walkthrough is for you. We will cover mocking external libraries and HTTP calls, property based testing, and using a snapshot testing library to make writing tests easier, faster and more fun! Mocking libraries allows us to test a code interface without requiring the underlying code to be run. This can be useful in testing databases and network requests without having to actually setup a database, or be connected to the Internet. Property based testing checks that a particular property is satisfied by the code. Rather than list specific instances of a property, property based testing frameworks allow you to describe the property and (possibly) find counterexamples. Snapshot based testing is useful for regression tests - to capture the output of a system at a particular state and ensure that it does not change. While snapshot based testing can be emulated using the standard Python library, it can be cumbersome to manually keep track of outputs. Snapshot testing libraries help with this. A recording of this session is available on YouTube: https://youtu.be/ozOEXz7G0p4
Institutions
- Weatherford College (US)
Publication Details
- Journal
- Zenodo (CERN European Organization for Nuclear Research)
- Published
- 2024-12-06
- DOI
- https://doi.org/10.5281/zenodo.14290427
- Primary Topic
- Computational Physics and Python Applications
- Type
- article
- Field-Weighted Citation Impact
- 0.00