I have a test case that involves a rather large cartesian product(thousands of permutations) of a dictionary's keys/values. The function under test will spit out a list
of MD5 sums each with a 1-1 correspondence to a given permutation.
Function under test:
def get_all_perms():
... return big list of MD5 sums
I am trying to use pytest fixtures to generate the permutation space. As such I have a bunch of composed fixtures as follows:
@pytest.fixture(params=[True,False])
def build_pair_1(request):
return ('KEY_1', request.param)
@pytest.fixture(params=[True,False])
def build_pair_2(request):
return ('KEY_2', request.param)
@pytest.fixture(params=[True,False])
def build_pair_3(request):
return ('KEY_3', request.param)
@pytest.fixture
def build_dict(build_pair_1, build_pair_2, build_pair_3)
return dict([
build_pair_1,
build_pair_2,
build_pair_3,
])
@pytest.fixture
def get_sums(build_dict):
return sum(build_dict)
This does an excellent job of creating all the permutations. But if my understanding is correct and I add get_sums
to a test as an argument I'll get a test execution per sum. What I need to do is take the resulting set of permutations from get_sums
, stuff it into a list, and compare it to the result of my function under test. Something akin to...
def test_result_of_get_all_perms:
result = get_all_perms()
for sum in get_sums():
assert sum in result
Is there a way to iterate of the result of a fixture?
Aucun commentaire:
Enregistrer un commentaire