pytest-dev / pytest-dev/pytest

Marking fixtures as always-indirect

Open
#10,101 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

topic: fixtures type: proposal
Dominant language
Python
Stars
14.5k
Forks
3.4k
Avg merge
2d 9h
Merged PRs (30d)
35

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No files, tests, or entry points are named. Start by locating pytest's fixture decorator and parametrization handling, then trace how indirect parameters are currently selected. Done means supporting @pytest.fixture(indirect=True) with the stated indirect behavior and non-parametrized usage restrictions, backed by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing-qa
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.