Python Testing with pytest, Second Edition: Question About Test Fixures (Page 31)

#book-python-testing-with-pytest-second-edition

On page 31 it talks about the file ch3/test_fixtures.py

In that file there is also another example as follows:

@pytest.fixture()
def some_other_data():
    """Raise an exception from fixture."""
    x = 43
    assert x == 42
    return x


def test_other_data(some_other_data):
    """Try to use failing fixture."""
    assert some_data == 42

I am just wondering why the assertion here is for some_data instead of some_other_data which is passed into it?

Do we want the test_other_data test to use the some_data fixture instead of the some_other_data fixture?

It doesn’t seem to affect the outcome. I can change the name of some_data aswell as the value to anything it seems as the assertion error is raised from the some_other_data fixure.

Apologies if this is a silly question.

1 Like