Subtests
Subtests
Posted Nov 11, 2025 9:48 UTC (Tue) by fishface60 (subscriber, #88700)In reply to: Subtests by Lord_Gaav
Parent article: Pytest 9.0.0 released
It's not uncommon to have a relatively slow operation produce a result that has multiple values to check e.g. it produces a json document that needs to have multiple fields validated.
If you were to use parametrization or a bunch of other test functions for this you would need a common fixture, which makes it ambiguous where the failure is since all those tests share the fixture, and if you need to parametrize the fixure that adds yet more complexity.
Instead you can save the complexity of parameters for what you're passing to the function you're testing by putting your assertions within subtests so they don't terminate the test and you can test all of the properties instead of stopping at the first error.
