pytest-dev / pytest-dev/pytest

rootdir is not considered as expected

Open
#11,186 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

note

I made a repository to reproduce the bug: https://github.com/roeniss/pytest-bug-rootdir

issue
> tree 
.
├── settings
│   └── pytest.ini
└── test
    └── test_hello.py

> pytest -c settings/pytest.ini
=== test session starts === 
platform darwin -- Python 3.11.4, pytest-7.4.0, pluggy-1.2.0
rootdir: /Users/roeniss/tmp/pytest-error-reproduce/settings
configfile: pytest.ini
collected 1 item

settings/test/test_hello.py .                                                                                                                       [100%

=== 1 passed in 0.00s ===  

As we can see above, settings/test/test_hello.py doesn't exist. I came up with some idea:

  1. rootdir is just a string placeholder for readability. It is set as the configuration's directory by default and does not affect any actual test run. So this is the expected output.
  2. rootdir is something that is considered as source root or test root, meaning that this is a real bug. What should happen here is that no test has run because settings directory has no test.
  3. rootdir is worked but somehow it fallbacks to root path because there is no test in settings or any reason. Then it starts finding test and find it, run, but sadly the output shows wrong directory. So the log-side should be fixed.

I brought this bug here because I'm not sure what rootdir actually does. Is there any correct assumption on my thought?

versions
> pip list
Package    Version
---------- -------
iniconfig  2.0.0
packaging  23.1
pip        23.1.2
pluggy     1.2.0
pytest     7.4.0
setuptools 67.6.1

> pytest --version
pytest 7.4.0

> neofetch
                    'c.          roeniss@Roenissui-MacBookAir-2.local
                 ,xNMM.          ------------------------------------
               .OMMMMo           OS: macOS 13.2.1 22D68 arm64
               OMMM0,            Host: Mac14,2
     .;loddo:' loolloddol;.      Kernel: 22.3.0
   cKMMMMMMMMMMNWMMMMMMMMMM0:    Uptime: 5 days, 15 hours, 30 mins
 .KMMMMMMMMMMMMMMMMMMMMMMMWd.    Packages: 278 (brew)
 XMMMMMMMMMMMMMMMMMMMMMMMX.      Shell: zsh 5.8.1
;MMMMMMMMMMMMMMMMMMMMMMMM:       Resolution: 2048x1152
:MMMMMMMMMMMMMMMMMMMMMMMM:       DE: Aqua
.MMMMMMMMMMMMMMMMMMMMMMMMX.      WM: Rectangle
 kMMMMMMMMMMMMMMMMMMMMMMMMWd.    Terminal: iTerm2
 .XMMMMMMMMMMMMMMMMMMMMMMMMMMk   Terminal Font: JetBrainsMono-Regular 11
  .XMMMMMMMMMMMMMMMMMMMMMMMMK.   CPU: Apple M2
    kMMMMMMMMMMMMMMMMMMMMMMd     GPU: Apple M2
     ;KMMMMMMMWXXWMMMMMMMk.      Memory: 1487MiB / 8192MiB
       .cooc,.    .,coo:.



  • a detailed description of the bug or problem you are having
  • output of pip list from the virtual environment you are using
  • pytest and operating system versions
  • minimal example if possible

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 behavior with pytest -c settings/pytest.ini using settings/pytest.ini and test/test_hello.py from the linked example. Start by tracing how pytest reports rootdir and resolves the test path, then compare that behavior with the expected meaning of rootdir. Done means the intended behavior is established and the path or documentation issue is clearly identified.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli, testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.