Struggling to manage complex test scenarios in pytest? Try out Param Classes as a way of organizing and enriching your parameters!

https://sirosen.net/2026/02/27/pytest-param-classes.html

(Thanks to @nedbat for the inspiring material and encouraging words! Nothing helps me get things done quite like saying in public that I'm going to do them. 😅 )

Stephen Rosen

@sirosen @nedbat I've loved the typing.NamedTuple for this exact use case. Love to see the technique spreading.
@pathunstrom @sirosen Do you have an example?
@nedbat @sirosen I'd have to dig, but it's the same idea just using NamedTuple instead of dataclass to define the inputs and expected values.

@pathunstrom @nedbat
I still use namedtuple sometimes for fixtures, where str doesn't matter.

Recently I recall using it to bundle together a family of mocks for a context manager and several of its methods, applied via a fixture. That resulted in
```
mock_foo.constructor.assert_called_once_with(...)
mock_foo.bar.assert_not_called()
...
```

I feel like it deserves a different name from "param class" though... 🤔

@sirosen This is great, thanks. I wish there were a way to use a class and also have the test function take individual arguments without having to unpack them in the test function :(