Skip to content

Instantly share code, notes, and snippets.

@Ricyteach
Created November 15, 2021 14:58
Show Gist options
  • Save Ricyteach/a68b55eae065ddfdeb961bbb8e8fe016 to your computer and use it in GitHub Desktop.
Save Ricyteach/a68b55eae065ddfdeb961bbb8e8fe016 to your computer and use it in GitHub Desktop.
fixture parallelization using the pytest.mark.parameterize indirect=True argument
import pytest
@pytest.fixture(name="keys")
def keys_fixture(request):
"""A seq of keys"""
return request.param
@pytest.fixture(name="values")
def values_fixture(request):
"""A seq of values"""
return request.param
@pytest.fixture(name="a_dict_from_kv_pairs")
def a_dict_from_kv_pairs_fixture(keys, values):
"""An initialized dict from a seq of keys and values"""
return dict(zip(keys, values))
some_keys_and_values = [
# keys values
[("a", "b", "c"), (1, 2, 3)],
[("x", "y", "z"), (None, (), object())],
]
parametrize_some_keys_and_values = pytest.mark.parametrize("keys, values", some_keys_and_values, indirect=True)
@parametrize_some_keys_and_values
def test_a_dict_from_kv_pairs_truthy(a_dict_from_kv_pairs):
assert a_dict_from_kv_pairs
@parametrize_some_keys_and_values
def test_a_dict_from_kv_pairs_getitem(keys, values, a_dict_from_kv_pairs):
for k,v in zip(keys, values):
assert a_dict_from_kv_pairs[k] == v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment