Pull requests

#25 Merged
witsch witsch
hpk42 hpk42

fixture support in doctests

  1. Andreas Zeidler avatarAndreas Zeidler

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:

>>> browser = getfixture('browser')
>>> browser.open('some_url')

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… ;))

Comments (11)

  1. Andreas Zeidler author

    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?

  2. holger krekel repo owner

    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.

  3. Andreas Zeidler author


    you're right, i should follow up on this. sorry. i'll try to add the missing test this week. i can probably take some time on wednesday...

    thanks for the nudge! :)

  4. Andreas Zeidler author

    i've finally updated the pull request, removing the extra fixture_request and adding tests as well as (minimal) documentation. please let me know if there's anything missing...

  5. holger krekel repo owner

    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.

  6. Christian Klinger

    hi does this solution works with conftest.py files. for example a have a modul tests with an conftest.py and a test_app.txt. But i can not access my fixture any ideas?

  7. Nicolas Dietrich

    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:

    pytest_plugins = 'mypackage.mymodule'

    The fixtures declared in that module can then be fetched from doctests with the getfixture function.

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.