Skip to content Skip to sidebar Skip to footer

Calling Function That Yields From A Pytest Fixture

In my unit tests, I have two very similar fixtures, and I was hoping to break out some of the functionality into a helper function of some kind. Given my understanding of how yield

Solution 1:

You need to use yield from to be able to pass the generator through properly. Otherwise the generator object will be returned, which isn't recognized by pytest as a generator.

@pytest.fixture
def my_fixture_with_helper():
    yieldfromfixture_helper()

Much more information about yield from can be found at this stackoverflow post.

Post a Comment for "Calling Function That Yields From A Pytest Fixture"