[TIP] configure a pytest fixture

Bruno Oliveira nicoddemus at gmail.com
Wed Nov 16 04:59:59 PST 2016


On Wed, Nov 16, 2016 at 10:56 AM oliver <oliver.schoenborn at gmail.com> wrote:

>
>
> On Wed, Nov 16, 2016, 00:23 Florian Bruhin <me at the-compiler.org> wrote:
>
> Hi,
>
> * oliver <oliver.schoenborn at gmail.com> [2016-11-16 02:32:04 +0000]:
> > Thanks for the reply Bruno. I've used something like that in some
> fixtures
> > (actually returning a closure / lambda which, when called from the test,
> > returns a configured object), but it seems a little counter-intuitive
> (the
> > premise being that fixtures return objects ready to be used). How about
> > overloading the item operator [], so "def test(fixture[a,b])" would be
> > implemented in a similar way to annotations like "Map[str, int]" but
> > fixture[a,b] would allow the fixture function to receive a, b as
> > parameters.
>
> That's invalid Python syntax - fixture is an argument name here, not
> an object.
>
>
> Ah yes, rats! Then how about via a default value, this could easily be
> introspected by pytest:
>
> def test(fixture=a): would call fixture(a)
> def test(fixture=[a,b]): would call fixture(a, b)
>

Not sure if that's not abusing the syntax and confusing to some, after all
`fixture=1` seems like `fixture` would be `1`, but in fact could be
anything returned by the fixture.

My opinion is that I would not be a big fan of this.

Cheers,
Bruno.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20161116/40c861c7/attachment.htm>


More information about the testing-in-python mailing list