pytest-dev / pytest-dev/pytest

Some possible improvements in fixtures module

Open
#11,234 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Here are a list of possible improvements in pytest fixtures, initially introduced in #10771 .

Improvement Corresponding PR
Remove funcargs attribute from Callspec to unify parameters of the test item, as funcargs are transformed into pseudo-fixtures. #11220
Remove fixtures.py::add_funcarg_pseudo_fixture_def and care for transforming funcargs to pseudo fixturedefs right in MetaFunc.parametrize. #11220
Make FixtureArgKey to represent fixture param by its value rather than its index if possible, as does FixtureDef::cache_key . #11271
When parametrizing with multiple parametersets (or multiple tuples of params), index of parameters in a parameter set is determined by their index in the existing values of the parameter, not by the index of their parameter set in the parameter set list. This results in better identifying dependencies of tests, thus better reordering. #11257
Creating FixtureArgKey for representing fixture dependencies. #11231
Taking nonparametrized tests into consideration for reordering as well. Beforehand, only parametrized tests were considered, by retrieving their fixture dependecies. #11236
Remove fixtures.py::FuncFixtureInfo::prune_dependecy_tree and move its responsibility to very FixtureManager::getfixtureclosure. I note that populating arg2fixturedefs is done only once. #11243
Considering used shadowed fixture dependencies for reordering as well. This was done by changing fixturemanager::getfixtureclosure algo from BFS to DFS. #13789
Pruning dependency tree is done only if we have a metafunc.parametrize call within module-specific or class-specific pytest_generate_tests hooks. #11243
Fix a few typos, or tiny bugs and do a few small improvements #11277, #11284

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

Start by reviewing the linked PRs in the table and the fixture internals named there, including fixtures.py, MetaFunc.parametrize, FixtureManager::getfixtureclosure, and FuncFixtureInfo::prune_dependecy_tree. The listed improvements already correspond to pull requests, so completion would require identifying any remaining item and confirming its related tests and fixture-reordering behavior.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.