Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running a suite of pytest tests on multiple objects

Tags:

pytest

As a small part of a much larger set of tests, I have a suite of test functions I want to run on each of a list of of objects. Basically, I have a set of plugins, and a set of "plugin tests".

Naively, I can just make a list of test functions that take a plugin argument, and a list of plugins, and have a test where I call all of the former on all of the latter. But ideally, each test/plugin combo would appear as an individual test in the results.

Is there already a nicer/standardized way of doing something like this in pytest?

like image 237
Matt Chaput Avatar asked Nov 30 '25 20:11

Matt Chaput


1 Answers

Check out pytest's documentation on parametrization (https://pytest.org/latest/parametrize.html).

It's a mechanism for running the same test a number of times with different parameters -- it sounds like just what you want. It generates tests that run individually, and they have nice output and reporting.

like image 84
Frank T Avatar answered Dec 04 '25 17:12

Frank T



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!