Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support parameterized fixtures in doctests #13038

Open
staadecker opened this issue Dec 7, 2024 · 4 comments
Open

Support parameterized fixtures in doctests #13038

staadecker opened this issue Dec 7, 2024 · 4 comments

Comments

@staadecker
Copy link

staadecker commented Dec 7, 2024

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).

@RonnyPfannschmidt
Copy link
Member

I'm -1 on adding this to core

Fancy doctest addons should be investigated in plugins

@nicoddemus
Copy link
Member

Strange, it warrants investigation... if we already support autouse fixtures, I would expect parametrized fixtures to work too.

@RonnyPfannschmidt
Copy link
Member

Doctest collection doesn't invoke test generation

@nicoddemus
Copy link
Member

Hmm right.

At least we should document this limitation then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants