pytest
pytest copied to clipboard
Duplicate test nodeids in command line arguments show incorrect collection count but execute only once
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