0

I have a test with the following structure:

@pytest.fixture()
def foo():
    return 'foo'

@pytest.fixture()
def bar():
    return 'bar'

def test_foo_bar(foo, bar):
    assert foo + bar == 'foobar'

From my experiments, it appears that foo() called first, then bar(). This seems to follow the order which they are listed as parameters? Can I safely rely on this behavior?

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
  • https://stackoverflow.com/questions/25660064/in-which-order-are-pytest-fixtures-executed the solution there (and also in a [GitHub issue](https://github.com/pytest-dev/pytest/issues/805#issuecomment-116147688)) is to just have one fixture depend on the other, then return them both. – Nick T Sep 08 '17 at 16:53
  • @NickT Your comment would be more clear if you linked directly to the answer to which you are referring. – Code-Apprentice Sep 08 '17 at 16:56
  • The question is basically the same, asking in what order they're executed and how to control/guarantee it, and you're asking if the order is fixed/guaranteed. The second answer demonstrates how to force it. – Nick T Sep 08 '17 at 17:01
  • @NickT Thanks. The detail of "autouse" distracted me from the similarities of that question. – Code-Apprentice Sep 08 '17 at 17:04

0 Answers0