[TIP] Supplying variable options to unittest2 tests

Robert Collins robertc at robertcollins.net
Sun Jun 26 22:12:20 PDT 2016


On 23 June 2016 at 02:08, Perry Johnson <Perry.Johnson at efi.com> wrote:
> Hi all,
>
>
>
> I hope this is the right mailing list for this type of question, but I am
> trying to work with unittest to run through test cases, and I am just not
> understanding how to do what I need to do.  Knowledge wise I am a step up
> from beginner at Python, and I am without a formal CS degree.  If I should
> go to another list, please, let me know which one, and accept my apologies.

This is a totally fine list to use :).

> Here is the set up.
>
>
>
> I have a list of settings for software on a physical device which are test
> cases from a test case management application.  These cases involve setting
> options on the device through software, running a test, and checking the
> device's output.  I have set up a basic script to do the options setting,
> running, and checking.  I also have a framework supplied to me using
> unittest2 that will generate an html file with results of test cases run,
> using the unittest2.TestCase class.
>
>
>
> I would like to get each "test case" from the TCM application, run those
> settings through my script, and then get the results from the existing
> framework.  The trouble is I don't see a way to feed variable options into
> the unittest2.TestCase, and from what I have read this may not be what the
> module was designed for.  Creating individual test_ methods for every set of
> test case options is unwieldy because the options change, and there are
> thousands of tests.

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

HTH,
Rob



More information about the testing-in-python mailing list