[TIP] Test parameterisation: TestCase.subTest, testscenarios (was: Supplying variable options to unittest2 tests)

Ben Finney ben+python at benfinney.id.au
Mon Jun 27 17:15:12 PDT 2016

Robert Collins <robertc at robertcollins.net> writes:

> Sounds like you have a test parameterisation problem. the
> 'testscenarios' library[1] would be a decent fit for this - I wrote it
> to tackle problems such as the one you're having, and it is a unittest
> compatible library so should drop straight into your framework.
> [1] https://pypi.python.org/pypi/testscenarios

I am an enthusiastic user of ‘testscenarios’, it is a great way
toconcisely express data-driven tests that exercise the same logic on a
set of inputs.

In Python 3.4, the ‘unittest.TestCase’ API grew a “subtest” feature
which seems similar in intent but is rather different in operation.

so now we have the very capable ‘testscenarios’ third-party library, and
the rather different standard library ‘TestCase.subTest’ API.

What are people's thoughts on which to use and when? Are they
complementary, or is one clearly superior?

 \             “We can't depend for the long run on distinguishing one |
  `\         bitstream from another in order to figure out which rules |
_o__)               apply.” —Eben Moglen, _Anarchism Triumphant_, 1999 |
Ben Finney

More information about the testing-in-python mailing list