[TIP] configure a pytest fixture

Florian Bruhin me at the-compiler.org
Tue Nov 15 21:21:31 PST 2016


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.

If your fixture argument is static, another possibility which is used
sometimes is to use a marker on the test, and then getting that marker
from the fixture function via the 'request' object:
http://docs.pytest.org/en/latest/fixture.html#fixtures-can-introspect-the-requesting-test-context

Florian

-- 
http://www.the-compiler.org | me at the-compiler.org (Mail/XMPP)
   GPG: 916E B0C8 FD55 A072 | http://the-compiler.org/pubkey.asc
         I love long mails! | http://email.is-not-s.ms/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20161116/b1dd9f7e/attachment.pgp>


More information about the testing-in-python mailing list