Skip to content

Collection Incorrect When Specify Both Parent and Sub Folders #13319

Open
@hfudev

Description

@hfudev

Reproduce steps

# Create the main directory structure
mkdir -p test-pytest-collect/parent/sub1
mkdir -p test-pytest-collect/parent/sub2
mkdir -p test-pytest-collect/parent/sub3

# Create test files as one-liners
echo "def test_sub1(): pass" > test-pytest-collect/parent/sub1/test_sub1.py
echo "def test_sub2(): pass" > test-pytest-collect/parent/sub2/test_sub2.py
echo "def test_sub3(): pass" > test-pytest-collect/parent/sub3/test_sub3.py

go to test-pytest-collect folder, and install only pytest in venv


Expected

> pytest --collect-only -q
parent/sub1/test_sub1.py::test_sub1
parent/sub2/test_sub2.py::test_sub2
parent/sub3/test_sub3.py::test_sub3

3 tests collected in 0.00s

> pytest --collect-only -q parent/sub1
parent/sub1/test_sub1.py::test_sub1

1 test collected in 0.00s

Unexpected

> pytest --collect-only -q parent/sub1 parent/
parent/sub1/test_sub1.py::test_sub1

1 test collected in 0.00s

Metadata

Metadata

Labels

topic: collectionrelated to the collection phasetype: bugproblem that needs to be addressed

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions