This repository contains a small collection of helpers from a laboratory measurement workflow. The tests pass, but several less obvious inputs reveal shared state and silently altered data.
Work through the checkpoints in order. Each one is small and can be tested independently.
Create or activate a Python environment and install the development tools:
python -m pip install -r requirements-dev.txt
python -m pytestThe initial tests should pass. Read measurement_workflow.py before changing it, and predict which inputs might behave unexpectedly.
Call record_warning twice without supplying a list. Predict the result, then add a test that proves each call should start with an independent collection. Fix the mutable default argument without changing how callers use the function.
Next, add a test that checks the sum of measurements with values 0.1 and 0.2, using the function total_value. The scientific requirement is that the result is approximately 0.3; express that with pytest.approx instead of exact floating-point equality.
Run only your new tests while working, for example:
python -m pytest -k "warning or total"Choose descriptive test names of your own. The autograder checks whether the tests detect the problematic behaviors; it does not require the names used in the instructor solution.
In effective_tolerance, the value 0.0 is a valid request for an exact tolerance. Add a test for it, then fix effective_tolerance so that only None selects the default.
parse_measurement currently turns every parsing failure into 0.0. That makes malformed input look like a real measurement. Add a test using an invalid value such as "not-a-number" and check that it raises ValueError. Then remove the broad exception handling and let the original parsing error propagate.
Do not silently invent a replacement measurement. The original ValueError already identifies the invalid text and preserves the useful traceback.
Run all project checks:
python -m pytest
python -m ruff format --check .
python -m ruff check .Inspect the changes before committing them:
git diff
git status
git add measurement_workflow.py tests/test_measurement_workflow.py
git commit -m "Make the measurement workflow safer"
gh student submitThe automated checks are feedback, not the purpose of the exercise. If a checkpoint takes too long, continue with the next one and compare approaches with another participant or the reference solution afterward.