pytest-dev / pytest-dev/pytest

`testpaths` is ignored when specifying the config file with `-c`

Open
#9,723 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

$ pip list
Package    Version
---------- -----------------------
attrs      21.4.0
iniconfig  1.1.1
packaging  21.3
pip        21.1.3
pluggy     1.0.0
py         1.11.0
pyparsing  3.0.7
pytest     7.1.0.dev236+ge466a87bb
setuptools 56.0.0
tomli      2.0.1
Minimal example
# <dir>/pytest.ini
[pytest]
testpaths = tests1
# <dir>/tests1/test_1.py
def test_1():
    assert True
# <dir>/dir1/pytest.ini
[pytest]
testpaths = tests2
# <dir>/dir1/tests2/test_2.py
def test_2():
    assert False
Steps to reproduce

Run pytest commands from the <dir>

$  pytest --collect-only

platform darwin -- Python 3.9.6, pytest-7.1.0.dev236+ge466a87bb, pluggy-1.0.0
rootdir: /Users/pacahon/Downloads/tmp/pytest, configfile: pytest.ini, testpaths: tests1
collected 1 item

<Module tests1/test_1.py>
  <Function test_1>

$ pytest -c dir1/pytest.ini --collect-only

platform darwin -- Python 3.9.6, pytest-7.1.0.dev236+ge466a87bb, pluggy-1.0.0
rootdir: /Users/pacahon/Downloads/tmp/pytest/dir1, configfile: pytest.ini
collected 2 items

<Module tests2/test_2.py>
  <Function test_2>
<Module test_1.py>
  <Function test_1>
Expected behavior

1 collected item while executing the second command + testpaths info in the output headers (since dir1 is the rootdir). Something like this:

$ pytest -c dir1/pytest.ini --collect-only

platform darwin -- Python 3.9.6, pytest-7.1.0.dev236+ge466a87bb, pluggy-1.0.0
rootdir: /Users/pacahon/Downloads/tmp/pytest/dir1, configfile: pytest.ini, testpaths: tests2
collected 1 item

<Module tests2/test_2.py>
  <Function test_2>

P.S: I experience the same behaviour with 7.0.1 from pypi. 6.2.5 gives me an error ERROR: file or directory not found: tests2
P.P.S. Maybe related to https://github.com/pytest-dev/pytest/issues/9703

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

Reproduce the two pytest --collect-only commands using the shown pytest.ini files and -c dir1/pytest.ini. Start by tracing how testpaths, rootdir, and the explicitly selected config are handled during collection. Done means the second command collects only tests2/test_2.py and reports testpaths: tests2 in its header.

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
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.