import pytest
def create_list():
"""Return the list of test values."""
return [1, 2, 3, 4]
def pytest_generate_tests(metafunc):
if "value" in metafunc.fixturenames:
# Directly use the function instead of treating it as a fixture
values = create_list()
metafunc.parametrize("value", values)
def test_print_each_value(value):
"""This test runs once per value from create_list()."""
assert isinstance(value, str) # will fail since value is int
print(f"Testing value: {value}")
This seems to be the way to yield values from a list generated by a different function. The pytest_generate_tests hook generates a parametrized call to a function, in this case the fixture named "value".