[pytest-dev] Introspecting fixtures from within a test

Raphael Pierzina raphael at hackebrot.de
Sat Jan 16 10:26:00 EST 2016


Hi Christoph,

you can retrieve the used fixtures from the test node and use named function right after.

See https://gist.github.com/hackebrot/848ab671583540fe18d1 <https://gist.github.com/hackebrot/848ab671583540fe18d1>

Hope this helps!
Raphael

> On 16 Jan 2016, at 13:43, Christoph Buelter <c.buelter at arcor.de> wrote:
> 
> Hi there,
> 
> I have a small question about fixtures. Basically inside a test function I would like to know  which fixtures are active/avaialable and I want to be able to reference them and get their return values.
> 
> @pytest.fixture
> def inner():
>     return 1
> 
> @pytest.fixture
> def foo(inner):
>     return 2
> 
> @pytest.fixture
> def bar():
>     return 3
> 
> @pytest.mark.bar
> def test_foo(foo):
>     # Let's assume the 'bar' mark magically requests the bar fixture.
>     # Now all of 'inner', 'foo' and 'bar' should be available in here.
>     # Is there a way to actually reference them here and get their 
>     # return values, e.g. like: request.getfuncargvalue(...) but 
>     # only for fixtures that have alreay been requested?
>     pass
> 
> I hope that makes sense to you. I am new to pytest development, so if there is a section in the docs that covers this that I have missed, any pointers would be greatly appreciated.
> 
> Cheers,
> Christoph
> 
> 
> _______________________________________________
> 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/20160116/6458bd23/attachment.html>


More information about the pytest-dev mailing list