@@ -289,51 +289,30 @@ are finalized when the last test of a *package* finishes.
289289 Use this new feature sparingly and please make sure to report any issues you find.
290290
291291
292- Higher-scoped fixtures are instantiated first
293- ---------------------------------------------
292+ Order: Higher-scoped fixtures are instantiated first
293+ ----------------------------------------------------
294294
295295
296296
297297Within a function request for features, fixture of higher-scopes (such as ``session ``) are instantiated first than
298298lower-scoped fixtures (such as ``function `` or ``class ``). The relative order of fixtures of same scope follows
299- the declared order in the test function and honours dependencies between fixtures.
299+ the declared order in the test function and honours dependencies between fixtures. Autouse fixtures will be
300+ instantiated before explicitly used fixtures.
300301
301302Consider the code below:
302303
303- .. code-block :: python
304-
305- @pytest.fixture (scope = " session" )
306- def s1 ():
307- pass
308-
309-
310- @pytest.fixture (scope = " module" )
311- def m1 ():
312- pass
313-
314-
315- @pytest.fixture
316- def f1 (tmpdir ):
317- pass
318-
319-
320- @pytest.fixture
321- def f2 ():
322- pass
323-
324-
325- def test_foo (f1 , m1 , f2 , s1 ):
326- ...
327-
304+ .. literalinclude :: example/fixtures/test_fixtures_order.py
328305
329306The fixtures requested by ``test_foo `` will be instantiated in the following order:
330307
3313081. ``s1 ``: is the highest-scoped fixture (``session ``).
3323092. ``m1 ``: is the second highest-scoped fixture (``module ``).
333- 3. ``tmpdir ``: is a ``function ``-scoped fixture, required by ``f1 ``: it needs to be instantiated at this point
334310 because it is a dependency of ``f1 ``.
335- 4. ``f1 ``: is the first ``function ``-scoped fixture in ``test_foo `` parameter list.
336- 5. ``f2 ``: is the last ``function ``-scoped fixture in ``test_foo `` parameter list.
311+ 3. ``a1 ``: is a ``function ``-scoped ``autouse `` fixture: it will be instantiated before other fixtures
312+ within the same scope.
313+ 4. ``f3 ``: is a ``function ``-scoped fixture, required by ``f1 ``: it needs to be instantiated at this point
314+ 5. ``f1 ``: is the first ``function ``-scoped fixture in ``test_foo `` parameter list.
315+ 6. ``f2 ``: is the last ``function ``-scoped fixture in ``test_foo `` parameter list.
337316
338317
339318.. _`finalization` :
0 commit comments