how would one run a single test out of a set configured with parametrize? let's say i have the following test method:

@pytest.mark.parametrize(PARAMETERS_LIST, PARAMETERS_VALUES)
def test_my_feature(self, param1, param2, param3):
    test doc
    if param1 == 'value':
        assert True
        print 'not value'
        assert False

i have 3 parameters and I generate a list of 15 different possible values for them, to test the function on. how would i run just one of them? except the obvious way - giving a single value instead of 15.

2 Answers

Enrique Saez On Best Solutions

You can specify the tests to run by using the -k flag for filtering tests that match a string expression. When using parametrize, pytest names each test case with the following convention:

test_name['-' separated test inputs]

for example


Selecting an specific test to run is a matter of putting all the above together for example

pytest -k my_test[value_1-value_2]
lmiguelvargasf On

I can think of two possible solutions.

  1. Use the name of the test you want to run, and execute it
  2. Use the -k parameter to run tests that match a given substring expression

Solution 1

Use the following command to see the name of the tests without running them:

pytest --collect-only -q

Use the name of the test you want to run, let's say the test is called[value1-value2-value3], so use the following command to run it:


Solution 2

This solution has been provided by Enrique Saez, and it basically consists of passing part of the name of the test:

pytest -k -value3]