[TIP] How to control combinations of parameterization in pytest?

Bruno Oliveira nicoddemus at gmail.com
Fri May 19 08:38:28 PDT 2017


Hi Arun,

The only way I can think of to approach this is to explicitly skip the test
if the known invalid combination is given:

invalid_combinations = [(val1, val2), (val2, val1)]
def test_1(moduleFixture, functionFixture):
   '''
   does tests...
   '''

   pair = (moduleFixture.val, functionFixture.val)
   if pair in invalid_combinations:
      pytest.skip('invalid combination: {}'.format(pair))

Hope that helps.
Bruno
​

On Fri, May 19, 2017 at 11:07 AM arun kali raja <arunsep886 at gmail.com>
wrote:

> Hi all,
>
> My test.py file looks something like this:
>
> test.py
>
> pytest_generate_tests(metafunc):
>    metafunc.parametrize('moduleFixture',[val1,val2],indirect=True,scope='module')
>    metafunc.parametrize('functionFixture',[val1,val2],indirect=True,scope='function')
> @pytest.fixture(scope='module')def moduleFixture(request):
>    '''
>    does something
>    '''
> @pytest.fixture(scope='function')def functionFixture(request):
>    '''
>    does something
>    '''
> def test_1(moduleFixture, functionFixture):
>    '''
>    does tests...
>    '''
>
> If i actually using pytest it generates 4 Testcases
>
> test_1 [val1-val1]
> test_1 [val1-val2]
> test_1 [val2-val1]
> test_1 [val2-val2]
>
> But actually, val1-val2 and val2-val1 are invalid combinations for me!! :(
>
> now how do control the permutation combinations and make sure that my
> testcase skips for these wrong combinations?
> [
> Have posted the same in stackOverflow too..
>
>
> http://stackoverflow.com/questions/44072081/how-to-control-combinations-of-parameterization-in-pytest
>
> ]
> --
> B.Arun Kaliraja
> _______________________________________________
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
> http://lists.idyll.org/listinfo/testing-in-python
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20170519/6ce87a25/attachment-0001.htm>


More information about the testing-in-python mailing list