pytest-dev / pytest-dev/pytest

`pytest_generate_tests` conflicts with `conftest.py` fixtures

Open
#2,726 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Dedicated repository for exhibiting the problem and with detailed description see https://github.com/vlcinsky/pytest_generate_tests-conflicts

From "summary" in repository README.md

Duplicate values

As shown in 003_conftest_fixt1, when pytest_generate_tests provided a value for test case
parameter and at the same time conftest.py provides a fixture with the same name, it wrongly
attempts to define a test case call also with the value from conftest.py fixture.

Expected behaviour is, that once a test function gets value for a parameter from
pytest_generate_tests, then further collection of values for this parameter shall stop.
Alternatively it shall resolve the duplication by giving the pytest_generate_tests parameter value
preference.

Collection collects tests multiple times

As shown in 005_conftest_fixt2, when pytest_generate_tests provides a value for a test case
parameter and at the same time in conftest.py there exist a fixture, which is dependent on another
one, it results in collecting the same test call (having the same combination of parameter values)
multiple times, this time it goes around Duplicate values by generating new test id using
parameter value from conftest.py fixture.

Expected behaviour is the same as described in "Duplicate values" above.

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 with the linked reproduction repository and its README, especially cases 003_conftest_fixt1 and 005_conftest_fixt2, to reproduce both duplicate-value and repeated-collection behaviors. Trace the pytest collection and fixture interactions involved, then verify that parameters supplied by pytest_generate_tests take precedence and each test call is collected only once.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.