A (hopefully) beginner-friendly workshop about Python testing tailored to academic and research code. The workshop was held at DACH+ Linz and OpenMod Freiburg 2026.
The repository contains a small example simulation in which a battery stores surplus PV energy and supplies it later when the PV system does not generate enough electricity to cover the load.
python_testing_research/battery.pycontains the battery model. It handles charging and discharging the battery without exceeding it's limits.python_testing_research/controller.pydefines the self-consumption controller. It requests charging the battery when there is excess PV generation and discharging when the load is higher than PV generation.python_testing_research/simulation.pycreates a sample load and PV profile and runs a time step simulation of the battery.tests/this is where the workshop exercises take place.
- Fork this repo
- Clone your fork
- Recommended: Create a virtual Python or conda environment (and activate it)
- Install package with
python -m pip install -e .(don't forget the-e: it is important!) - Test the installation with
python -m pytest testsin the project root. If you see passing tests you are good to go ;-) - Run the simulation with
python -m python_testing_research.simulation(or runsimulation.pywithin your IDE). Also, spend a few minutes reviewingsimulation.pyandbattery.py. You do not need to understand every detail, but familiarizing yourself with the code beforehand will make your life easier during the workshop and allow you to focus on the testing concepts introduced there.
This repository uses split licensing:
- The source code in this repository is licensed MIT. See
LICENSEfile at the repository root. - The presentation materials in
slides/are licensed under CC BY-NC-SA 4.0.