I'm working on some fairly complicated test scenarios with PyTest, and I was hoping to encapsulate the test setup for various scenarios in some functions and then make those scenarios available to a test using parameterization.
Here is a simplified example:
def scenario01():
# complicated setup
...
return {
"name": "scenario01",
"cond1": cond1,
"cond2": cond2
}
def scenario02():
# complicated setup
...
return {
"name": "scenario02",
"cond1": cond1,
"cond2": cond2
}
# is it ok to call these functions in the decorator
@pytest.mark.parametrize("test_data", [scenario01(), scenario02()])
def test_my_func(test_data):
name = test_data["name"]
cond1 = test_data["cond1"]
cond2 = test_data["cond2"]
assert cond1 && cond2 #this isn't important
Is there any downside to doing something like this?
I like this because, as a reader, its obvious where the fixtures are coming from and their not magically defined in some conftest.py file, but I'm not sure if there is some side effects that may be happening that I'm not aware of.