Repository navigation
Closed
Description
Please see the below simple reproduction of the problem. When mixing relative and absolute path configuration file resolution as per https://pytest.org/latest/customize.html
First execution just relative path (finds pytest.ini)
Second execution with relative and absolute (does not find pytest.ini)
Third execution with argument -s between relative and absolute path (does find pytest.ini)... strange...
➜ plauri@Peters-MacBook-Pro pytest-abs-rel-bug ls -lrt dir1 dir2
dir1:
total 16
-rw-r--r-- 1 plauri staff 23 Aug 19 14:34 pytest.ini
-rw-r--r-- 1 plauri staff 35 Aug 19 14:36 test_hello.py
drwxr-xr-x 3 plauri staff 102 Aug 19 14:37 __pycache__
dir2:
total 8
-rw-r--r-- 1 plauri staff 35 Aug 19 14:37 test_hola.py
drwxr-xr-x 3 plauri staff 102 Aug 19 14:38 __pycache__
➜ plauri@Peters-MacBook-Pro pytest-abs-rel-bug cat dir1/pytest.ini
[pytest]
addopts = -vv
➜ plauri@Peters-MacBook-Pro pytest-abs-rel-bug cd dir1
➜ plauri@Peters-MacBook-Pro dir1 ../.ve/bin/py.test test_hello.py
=================================================== test session starts ====================================================
platform darwin -- Python 2.7.10 -- py-1.4.30 -- pytest-2.7.2 -- /Users/plauri/work/play/pytest-abs-rel-bug/.ve/bin/python2.7
rootdir: /Users/plauri/work/play/pytest-abs-rel-bug/dir1, inifile: pytest.ini
collected 1 items
test_hello.py::test_ok PASSED
================================================= 1 passed in 0.00 seconds =================================================
➜ plauri@Peters-MacBook-Pro dir1 ../.ve/bin/py.test test_hello.py /Users/plauri/work/play/pytest-abs-rel-bug/dir2
=================================================== test session starts ====================================================
platform darwin -- Python 2.7.10 -- py-1.4.30 -- pytest-2.7.2
rootdir: /Users/plauri/work/play/pytest-abs-rel-bug, inifile:
collected 2 items
test_hello.py .
../dir2/test_hola.py .
================================================= 2 passed in 0.01 seconds =================================================
➜ plauri@Peters-MacBook-Pro dir1 ../.ve/bin/py.test test_hello.py -s /Users/plauri/work/play/pytest-abs-rel-bug/dir2
=================================================== test session starts ====================================================
platform darwin -- Python 2.7.10 -- py-1.4.30 -- pytest-2.7.2 -- /Users/plauri/work/play/pytest-abs-rel-bug/.ve/bin/python2.7
rootdir: /Users/plauri/work/play/pytest-abs-rel-bug/dir1, inifile: pytest.ini
collected 2 items
test_hello.py::test_ok PASSED
::test_ok <- ../dir2/test_hola.py PASSED
================================================= 2 passed in 0.01 seconds =================================================
➜ plauri@Peters-MacBook-Pro dir1
Metadata
Metadata
Assignees
Labels
No labels
Activity
peterlauri commentedon Aug 19, 2015
As a workaround one could set the -c CONFIGFILE option.
ionelmc commentedon Aug 19, 2015
One way to solve this would be changing
determine_setupto look for conf files in CWD first, and then look in the common ancestors for all the test paths.nicoddemus commentedon Aug 25, 2015
Hmm accordingly to the docs in determining rootdir and inifile, because there are no
pytest.inifile in common ancestors for bothdir1anddir2, the correct behavior in my opinion is the one you get whenever you pass both directories, either in absolute or relative form.The fact that you pass
-sand suddenly it finds apytest.inifile seems to me to be a bug in how the arguments are parsed.Consider:
When I execute
py.testpassing the directories either as relative or absolute paths, I always get the same result, no pytest.ini file is found:(omitting some output for brevity)
But if I pass a flag (say
-sor-v) then suddenly the second path is not passed anymore todetermine_setupfunction, and then it finds thepytest.ini:Note that it doesn't find
pytest.iniif I switch the argument order, as there's nopytest.iniindir2:Paths after normal options are now properly used to discover rootdir …
peterlauri commentedon Aug 27, 2015
I don't think they are related. The example of having an option that makes it work, was just an extra side note. This is related to not finding the pytest.ini at all, without the option.
peterlauri commentedon Aug 27, 2015
I think this issue is wrongly closed.
nicoddemus commentedon Aug 27, 2015
Based on your example and the documentation, it was not supposed to find a
pytest.iniat all.The documentation says:
In your example, your structure was as follows:
Consider the following scenarios (let's assume CWD is
pytest-abs-rel-bugfor all examples, relative or absolute paths don't matter as well):In this case, the common ancestor of the files given in the command line is
$CWD, which ispytest-abs-rel-bug, which does not contain apytest.inifile, so none is considered for this test run. This is fine and it is the expected behavior.In this situation, pytest shouldn't find any
pytest.inifile as well according to the documentation. But there was a bug where paths after an option (dir2, which comes after-s) were not being considered when finding the inifile. So what happened was that pytest was interpreting this as justpy.test dir1, which then found thepytest.inifile underdir1and used that for the session.Hope this explanation makes sense. 😅 Sorry for not posting an explanation before!