pytest
pytest copied to clipboard
Marking fixtures as always-indirect
What's the problem this feature will solve?
I'm developing a pytest plugin that allows users to easily configure their fixtures: https://pypi.org/project/pytest-paramark/
One of the things I need for the plugin to be useful, is making all parametrizations of a given fixture indirect by default, so that users don't need to add parametrize(..., indirect=[...])
to all their tests.
I think such a feature would be also useful on its own.
Describe the solution you'd like
Add an optional parameter, so that one can write @pytest.fixture(indirect=True)
. This would:
- make all parametrizations of this fixture indirect
- disallow non-parametrized usage, unless the fixture provides defaults for all its arguments
Alternative Solutions
I've tried monkeypatching pytest inside the plugin to add this argument, but this is brittle, as I needed to dig deep into pytest's internals. I'd rather have this included upstream, if possible.
Additional context
I'm happy to work on a PR if this is something you find interesting/useful.
Im on board with the idea, but i would like to investigate a better name for the parameter
Indirect is a bit hard to intuitively understand
Im on board with the idea, but i would like to investigate a better name for the parameter
Indirect is a bit hard to intuitively understand
Sure. I've opened a PR so that we can iterate there. Not sure if I can come up with a better name, though 😕.