79672786

Date: 2025-06-20 01:41:35
Score: 0.5
Natty:
Report link
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".

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Ariba Siddiqi