pytest-dev / pytest-dev/pytest

Duplicate test nodeids in command line arguments show incorrect collection count but execute only once

Open
#13,412 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Description:

When passing duplicate test nodeids in the command line arguments, pytest shows an incorrect collection count but only executes the test once.

Steps to Reproduce:

Run pytest with duplicate test nodeids:

pytest tests/test_foo.py::test_pass tests/test_foo.py::test_pass

Observed Behavior:

collected 2 items

tests/test_foo.py::test_pass PASSED                                      [100%]

============================== 1 passed in 0.01s ===============================

The output shows "collected 2 items" but only executes and reports 1 test

The progress percentage shows [100%] after one test

Expected Behavior:

Either:

Pytest should deduplicate the nodeids during collection and show "collected 1 item", or

Pytest should execute the test twice (if intentional duplicate execution is desired)

Environment:

pytest version: 8.3.5

Python version: 3.12

OS: macos

Additional Information:

This might cause confusion when:

Accidentally passing duplicate tests in complex command line invocations

Using tools that generate pytest command lines automatically

Trying to understand test counts in CI output

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 reproducing the command with the duplicate tests/test_foo.py::test_pass nodeid and trace how command-line nodeids are collected and reported. Done means the collection count, progress percentage, and executed test count consistently reflect the chosen duplicate-nodeid behavior, with coverage for this reproduction.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.