[TIP] unittest subtests

holger krekel holger at merlinux.eu
Sun Jan 20 01:28:28 PST 2013


Hi Chris,

On Sat, Jan 19, 2013 at 16:07 -0800, Chris Jerdonek wrote:
> Just thought I would let this list know about an issue/patch to add a
> sort of parametrized test functionality to unittest called subtests:
> 
> http://bugs.python.org/issue16997
> 
> It would be good to know how the proposed implementation plays with
> the various test frameworks that are out there.

Thanks, I am following that subtest idea.  As far as pytest is
concerned we have some related thoughts but - as in the above discussion -
it's not clear how it should interact with reporting, xfail test states,
let alone test addressability, plugin hooks, distributed testing and
fixture setup/teardown.  I guess that pytest can support whatever the
above hack results in -- will probably just add to the existing compat
code for running nose, unittest and trial tests.

However, i am not sure how the issue16997 example maps to the in-development 
unittest plugin branches.   Maybe Michael or Jason can shed some light.

Lastly, you can map the above example from the link easily to today's pytest:

    @pytest.mark.parametrize(("i", "j"), [(i,j)
                             for i in range(2,5) for j in range(0,3)])
    def test_b(i, j):
        assert i % 3 != j

which runs the test 9 times with the different "i, j" combinations passed
passed in.  As all of these 9 tests are "normal", there is no special code
or consideration needed for the above interaction issues.

best,
holger



More information about the testing-in-python mailing list