this is an attempt to support fixtures in doctests — or more specifically, doctest files — in response to the corresponding question on stackoverflow. the idea is to pass a FixtureRequest object as a global into the doctest, along with a convenience helper to retrieve a single fixture, where they can be used like so:
this seems to work fine in our project. the exact/best syntax is up for discussion, of course, but we thought the global might be a little less obscure than the .. pytest-fixtures: … line (and also easier to implement… ;))
yes, obviously... :) i'll add some, of course, but before i spend more time i wanted to discuss the general approach with you. so, do you think this is a good — or at least acceptable — way to tackle this issue?
Yes, I think exposing a "getfixture" function makes sense. Not sure about exposing the FixtureRequest itself - do you need this for your projects and if so, can you paste a little example? As it stands now, i wouldn't expose it because using it exposes too many details into a doctest - but then again, i am not much of a doctest user myself.
thanks Andreas, one last bit: could you rename the exposed function to "getfixture"? This better matches the current API style and i think i am going to introduce a "request.getfixture(...)" at some point.
Christian Klinger - from my testing using fixtures from conftest.py in doctests doesn't work yet. However, you can declare a pytest plugin, which is nothing more than a python module containing fixtures, in conftest.py:
The fixtures declared in that module can then be fetched from doctests with the getfixture function.