Two testing-related things I found recently.Unified exception testingKacper Borucki blogged about parameterizing exception
testing, and linked to pytest docs and a
StackOverflow answer with similar approaches.The common way to test exceptions is to use
pytest.raises as a context manager, and have
separate tests for the cases that succeed and those that fail. Instead, this
approach lets you unify them.I tweaked it to this, which I think reads nicely:from contextlib import nullcontext as produces import pytest
from pytest import raises @pytest.mark.parametrize( "example_input, result", [ (3, produces(2)), (2, produces(3)), (1, produces(6)), (0, raises(ZeroDivisionError)), ("Hello", raises(Typ…