I'm trying to parametrize pytest test with a function that yields values of parameters. I want it to run test separately for each value. Here is example code:
def provider():
yield pytest.param([1, 2])
class Test:
@pytest.mark.parametrize("a", provider())
def test(self, a, logger):
logger.info("a: {}".format(a))
@pytest.mark.parametrize("a", [1, 2])
def test_2(self, a, logger):
logger.info("a: {}".format(a))
Is it possible to parametrize test using provider function to make it work the way like test_2.
Here are my logs from above tests:
2019-12-09 14:39:36 test[a0] start
a: [1, 2]
2019-12-09 14:39:36 test[a0] passed
2019-12-09 14:39:36 test_2[1] start
a: 1
2019-12-09 14:39:36 test_2[1] passed
2019-12-09 14:39:36 test_2[2] start
a: 2
2019-12-09 14:39:36 test_2[2] passed