Skip to content

Support parameterized fixtures in doctests #13038

Open
@staadecker

Description

@staadecker

I'd like to be able to run all my doctests twice (once for each of my backends). This is essentially equivalent to a use case already described in your documentation. Here's what I'd like to do:

# conftest.py

@pytest.fixture(autouse=True, params=["backend_1", "backend_2"])
def _setup_before_each_test(request):
    my_library.global_setting_1 = request.param

This works fine for normal pytests (yay 🎉) but fails on doctests.

The requested fixture has no parameter defined for test:
    src/pyoframe/_arithmetic.py::pyoframe._arithmetic._get_dimensions
Requested fixture '_setup_before_each_test' defined in:
conftest.py:7
Requested here:
.venv\lib\site-packages\_pytest\fixtures.py:697

I was surprised considering the pytest documentation on doctests says "fixtures marked as autouse are supported".

Any suggested workarounds? What would be needed to add support for parameterized autouse fixtures in doctests?

Details on the error

Note that the error (as explained in #4666) seems to stem from the fact that doctest doesn't detect the parameterized fixture during collection which means that it fails at runtime (as it doesn't know which backend to use).

Metadata

Metadata

Assignees

No one assigned

    Labels

    plugin: doctestsrelated to the doctests builtin plugintopic: collectionrelated to the collection phasetopic: fixturesanything involving fixtures directly or indirectlytype: docsdocumentation improvement, missing or needing clarification

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions