[pytest-dev] Fixture ordering and scopes

Vasily Kuznetsov kvas.it at gmail.com
Fri Mar 16 06:16:50 EDT 2018

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. 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

Outer scopes running before inner scopes does sound kind of logical but
everything running lazily on demand (as it does now) also makes sense. If
asked to choose, I'd probably leave the order unspecified to help people
not forget to declare their dependencies and to have more flexibility of

Maybe this should be addressed with documentation instead.


On Fri, Mar 16, 2018 at 9:46 AM Floris Bruynooghe <flub at devork.be> wrote:

> Brian Okken <variedthoughts at gmail.com> writes:
> > I get numerous questions about it, and I always tell people to create
> > artificial dependencies between fixtures that need to run in a certain
> > order.
> I'm not sure I follow why you consider them to be *artificial*
> dependencies.  If a function-scoped fixture depends on anything of a
> session-scoped fixture, surely you'd rather have the dependency
> explicitly in your face rather then it slipping past by luck?
> > The general mental model that people have for fixtures is that they are
> run
> > in scope order.
> > I think the current behavior of file order overriding scope order is
> insane
> > and a bug.
> My general mental model of fixtures is that they are as lazy as
> possible.  This is probably also somewhat incorrect.
> _______________________________________________
> pytest-dev mailing list
> pytest-dev at python.org
> https://mail.python.org/mailman/listinfo/pytest-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pytest-dev/attachments/20180316/479941fe/attachment.html>

More information about the pytest-dev mailing list