[pytest-dev] Fixture ordering and scopes

Vasily Kuznetsov kvas.it at gmail.com
Fri Mar 16 08:18:26 EDT 2018


Hi Bruno,

Your example is a good argument, I haven't considered third party fixtures
over which the developer of the test suite has less control. I agree that
requiring users to jumps through extra hoops to give third-party fixtures
the desired order is too high of a price to pay for the nudge towards good
style (explicitly declaring dependencies) that we get from undefined order.

Once we decide to give some guarantees about the order of fixture execution
your new approach certainly makes sense.

Cheers,
Vasily

On Fri, Mar 16, 2018 at 12:34 PM Bruno Oliveira <nicoddemus at gmail.com>
wrote:

> 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/ff05dbf9/attachment.html>


More information about the pytest-dev mailing list