pytest icon indicating copy to clipboard operation
pytest copied to clipboard

Marking fixtures as always-indirect

Open mrzechonek opened this issue 2 years ago • 2 comments

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.

mrzechonek avatar Jul 04 '22 21:07 mrzechonek

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

RonnyPfannschmidt avatar Jul 05 '22 05:07 RonnyPfannschmidt

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