Repository navigation
Mixing relative and absolute paths to tests fails pytest.ini lookup #949
Description
Activity
As a workaround one could set the -c CONFIGFILE option.
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.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:
def determine_setup(inifile, args): print('determine_setup', args) if inifile: iniconfig = py.iniconfig.IniConfig(inifile) ...
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)
X:\temp\relbug\dir1>py.test test_dir1.py x:\temp\relbug\dir2 determine_setup ['test_dir1.py', 'x:\\temp\\relbug\\dir2'] ... rootdir: x:\temp\relbug, inifile:X:\temp\relbug\dir1>py.test x:\temp\relbug\dir1 x:\temp\relbug\dir2 determine_setup ['x:\\temp\\relbug\\dir1', 'x:\\temp\\relbug\\dir2'] rootdir: x:\temp\relbug, inifile:X:\temp\relbug\dir1>py.test x:\temp\relbug\dir1 ..\dir2 determine_setup ['x:\\temp\\relbug\\dir1', '..\\dir2'] rootdir: X:\temp\relbug, inifile: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:X:\temp\relbug\dir1>py.test x:\temp\relbug\dir1 -v ..\dir2 determine_setup ['x:\\temp\\relbug\\dir1'] rootdir: x:\temp\relbug\dir1, inifile: pytest.iniNote that it doesn't find
pytest.iniif I switch the argument order, as there's nopytest.iniindir2:X:\temp\relbug\dir1>py.test ..\dir2 -v ..\dir1 determine_setup ['..\\dir2'] rootdir: X:\temp\relbug\dir2, inifile:- added a commit that references this issue
on Aug 26, 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.
I think this issue is wrongly closed.
Based on your example and the documentation, it was not supposed to find a
pytest.iniat all.The documentation says:
1. determine the common ancestor directory for the specified args. 2. look for pytest.ini, tox.ini and setup.cfg files in the ancestor directory and upwards.In your example, your structure was as follows:
pytest-abs-rel-bug/ dir1/ pytest.ini dir2/Consider the following scenarios (let's assume CWD is
pytest-abs-rel-bugfor all examples, relative or absolute paths don't matter as well):$ py.test dir1 dir2In 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.$ py.test dir1 -s dir2In 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!
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...