pytest-dev / pytest-dev/pytest

Confusing interaction between rootdir and pytest.ini

Open
#6,376 4 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

From https://github.com/pytest-dev/pytest/issues/6359#issue-540390553:

Unfortunately I agree that the current interaction between rootdir and ini files is far from clear, and someone just looking at --rootdir would assume that it should point to the root of your repository/project, and from there on pytest would find pytest.ini files and start collection, but this is currently not the case.

I've seen more than one issue popping up about this confusion: people assume that --rootdir mydir implies that pytest will look for pytest.ini files and start collection from mydir, which is not the case at all currently.

I think we should change the meaning of --rootdir the option somehow, because I believe it is the main source of confusion, while I don't think it happens when rootdir is found automatically.

An initial proposal:

--rootdir when given:

  • Will set config.rootdir to that value (of course).
  • Will search from --rootdir and upwards for pytest.ini files.
  • If no paths are given in the command line, it will act like testpaths, where collection will be assumed to start from --rootdir.

Thoughts?

It is a change in existing behavior, but I think --rootdir is rarely used, and when used people are usually confused by it.

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

Read the referenced issue #6359 and investigate the current --rootdir behavior, including how pytest.ini discovery and collection roots are selected. Resolve the proposed semantics before implementation; done means the behavior is explicitly agreed and matches the resulting --rootdir rules.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli, testing
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.