mercredi 12 septembre 2018

Parametrize pytest test from within test function

I have a scenario I wish to test where I automatically generate parametrized versions of the test, basically fuzzing. However the parameters are generated based on some information gathered from the first test run. I currently solve this using a generator and a for loop but I'd prefer each scenario to be reported as an individual test case. Is this possible?

I cannot reasonably post my full code as it's very extensive, but it boils down to this:

def generate_scenarios():
    start_trace()
    yield
    end_trace()
    for scenario in generate_scenarios_from_trace():
        yield


def test_something():
    for scenario in generate_scenarios():
        assert something()

Aucun commentaire:

Enregistrer un commentaire