Skip to content

pytest main does not detect some invalid nodeid names #10273

Closed

Description

@elbehery95

Test scenario

test_file.py

import pytest

@pytest.mark.parametrize("bar", [1,2,3])
def test_foo(bar):
    print(bar)

The following invalid nodeid is accepted by pytest instead of printing an error

$ pytest "test_file.py[foobar]" -q

...        [100%]
3 passed in 0.04s

Expected

Similar to specifying wrong path/dir/parameterized nodeid an error should be printed instead of running all the tests in the given file

$ pytest "test_file.py[foobar]" -q

no tests ran in 0.01s
ERROR: file or directory not found: test_hello.py[foobar]

Activity

  1. added a commit that references this issue on Sep 5, 2022
  2. added
    type: bug
    topic: collection
    on Sep 27, 2022
  3. Zac-HD commented on Jul 22, 2026

    @Zac-HD
    Member

    Closing as resolved: fixed by #13717 (fixing #13716, pytest 9.0.0), which added validation in resolve_collection_argument so pytest "test_file.py[foobar]" now errors with "path cannot contain [] parametrization" instead of silently running all tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: collectiontype: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions