pytest-dev / pytest-dev/pytest

Collection Incorrect When Specify Both Parent and Sub Folders

Open
#13,319 1 comment 0 reactions 1 assignee View on GitHub

@farhannadim311 is already working on this.

Since Apr 27, 2025.

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

Description

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

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.