pytest-dev / pytest-dev/pytest

Parametrized nodeid not matching with parametrized IDs

Open
#4,142 10 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

This is about this issue in pytest-repeat: https://github.com/pytest-dev/pytest-repeat/issues/21

It seems that the bug doesn't come from the plugin: I managed to reproduce with a simple test here.
It affects all pytest versions, at least since 2.8

I wrote a test and a fix attempt here: https://github.com/vbarbaresi/pytest/commit/12769f0d3bda3c53426ba124e89f0072cc0b320b

The issue is the following: with parametrized IDs and parametrized fixtures, one can't run a test using its node ID with a [parameter] argument

I tracked it down to the x.name vs name matching, which is in my example:
test_foo[1-param] vs test_foo[param]

My fix attempt drops everything after [ on both sides. However, we lose the supplied parameter value so it's not satisfying. I don't know where to fix this properly.

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 simple parametrized test described in the issue and compare the node-ID matching behavior with the attempted fix in commit 12769f0d3bda3c53426ba124e89f0072cc0b320b. Trace the x.name versus name comparison, then verify that selecting a test by node ID works with parametrized fixtures and IDs while preserving the supplied parameter value.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing
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.