'Pytest duplicate test according to marker
I have the following problem: I created a marker called testParams and define 3 tests:
@pytest.mark.parametrize(
'name', [
pytest.param('1',id='p1', marks=pytest.mark.testParams("paramA")),
pytest.param('2',id='p2', marks=pytest.mark.testParams("paramB")),
pytest.param('3',id='no-p', marks=pytest.mark.testParams)
])
def test_t1(name,testParam):
print (name)
print ("run test with {}".format(testParam))
I want that when the parameter is not provided, 2 tests will be created with "paramA" and "paramB" and if a parameter is provided - the test will run with it. I know how to get the marker argument using item.get_closest_marker("testParams").args but how can I pass it into the test? Also, how can I duplicate test and change only relevant parameter? I tried to use the function pytest_collection_modifyitems in order to set new test or duplicate some but without success.
Please assist,
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
