[pytest-dev] Fixture ordering and scopes

Bruno Oliveira nicoddemus at gmail.com
Fri Mar 16 07:34:09 EDT 2018


Hi Vasily!

On Fri, Mar 16, 2018 at 7:17 AM Vasily Kuznetsov <kvas.it at gmail.com> wrote:

> I very much agree with Floris that if you need fixture A to run before
> fixture B and otherwise things break, this is called "dependency" and it's
> better if it's explicitly declared.
>

Definitely, if a fixture requires something that is done by another
fixture, then that dependency should be explicitly defined; but the issue
is more that people expect higher level scoped fixtures to be executed
first, and when you mix autouse fixtures and usefixtures markers, the order
is non-intuitive.



> I can't easily imagine a situation where declaring dependencies would be
> too much work or not desirable for some other reason but maybe it's just my
> imagination not being good enough :).
>

I wrote an example which demonstrates this in a separate reply to Floris.

Outer scopes running before inner scopes does sound kind of logical but
> everything running lazily on demand (as it does now) also makes sense.
>

Just to be clear, in my PR fixtures are still created lazily, it is just
that we sort them by scope (preserving order) first.

Cheers,
Bruno.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pytest-dev/attachments/20180316/5f20e07b/attachment.html>


More information about the pytest-dev mailing list