|
|
Log in / Subscribe / Register

Subtests

Subtests

Posted Nov 10, 2025 21:52 UTC (Mon) by Lord_Gaav (subscriber, #178078)
Parent article: Pytest 9.0.0 released

Subtests are working great, good alternative voor parametrize.


to post comments

Subtests

Posted Nov 11, 2025 9:48 UTC (Tue) by fishface60 (subscriber, #88700) [Link]

I think treating subtests as just an alternative to parametrization is underselling them.

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.


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds