Merge pull request #7822 from bluetech/backport-7813
[6.1.x] findpaths: fix regression causing incorrect rootdir to be determined
This commit is contained in:
		
						commit
						bcb94c4c8b
					
				| 
						 | 
					@ -0,0 +1 @@
 | 
				
			||||||
 | 
					Fixed regression in pytest 6.1.0 causing incorrect rootdir to be determined in some non-trivial cases where parent directories have config files as well.
 | 
				
			||||||
| 
						 | 
					@ -1,4 +1,3 @@
 | 
				
			||||||
import itertools
 | 
					 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
from typing import Dict
 | 
					from typing import Dict
 | 
				
			||||||
from typing import Iterable
 | 
					from typing import Iterable
 | 
				
			||||||
| 
						 | 
					@ -100,7 +99,7 @@ def locate_config(
 | 
				
			||||||
        args = [Path.cwd()]
 | 
					        args = [Path.cwd()]
 | 
				
			||||||
    for arg in args:
 | 
					    for arg in args:
 | 
				
			||||||
        argpath = absolutepath(arg)
 | 
					        argpath = absolutepath(arg)
 | 
				
			||||||
        for base in itertools.chain((argpath,), reversed(argpath.parents)):
 | 
					        for base in (argpath, *argpath.parents):
 | 
				
			||||||
            for config_name in config_names:
 | 
					            for config_name in config_names:
 | 
				
			||||||
                p = base / config_name
 | 
					                p = base / config_name
 | 
				
			||||||
                if p.is_file():
 | 
					                if p.is_file():
 | 
				
			||||||
| 
						 | 
					@ -184,9 +183,7 @@ def determine_setup(
 | 
				
			||||||
        ancestor = get_common_ancestor(dirs)
 | 
					        ancestor = get_common_ancestor(dirs)
 | 
				
			||||||
        rootdir, inipath, inicfg = locate_config([ancestor])
 | 
					        rootdir, inipath, inicfg = locate_config([ancestor])
 | 
				
			||||||
        if rootdir is None and rootdir_cmd_arg is None:
 | 
					        if rootdir is None and rootdir_cmd_arg is None:
 | 
				
			||||||
            for possible_rootdir in itertools.chain(
 | 
					            for possible_rootdir in (ancestor, *ancestor.parents):
 | 
				
			||||||
                (ancestor,), reversed(ancestor.parents)
 | 
					 | 
				
			||||||
            ):
 | 
					 | 
				
			||||||
                if (possible_rootdir / "setup.py").is_file():
 | 
					                if (possible_rootdir / "setup.py").is_file():
 | 
				
			||||||
                    rootdir = possible_rootdir
 | 
					                    rootdir = possible_rootdir
 | 
				
			||||||
                    break
 | 
					                    break
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1375,6 +1375,21 @@ class TestRootdir:
 | 
				
			||||||
        assert rootpath == tmp_path
 | 
					        assert rootpath == tmp_path
 | 
				
			||||||
        assert inipath is None
 | 
					        assert inipath is None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_with_config_also_in_parent_directory(
 | 
				
			||||||
 | 
					        self, tmp_path: Path, monkeypatch: MonkeyPatch
 | 
				
			||||||
 | 
					    ) -> None:
 | 
				
			||||||
 | 
					        """Regression test for #7807."""
 | 
				
			||||||
 | 
					        (tmp_path / "setup.cfg").write_text("[tool:pytest]\n", "utf-8")
 | 
				
			||||||
 | 
					        (tmp_path / "myproject").mkdir()
 | 
				
			||||||
 | 
					        (tmp_path / "myproject" / "setup.cfg").write_text("[tool:pytest]\n", "utf-8")
 | 
				
			||||||
 | 
					        (tmp_path / "myproject" / "tests").mkdir()
 | 
				
			||||||
 | 
					        monkeypatch.chdir(tmp_path / "myproject")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        rootpath, inipath, _ = determine_setup(None, ["tests/"])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        assert rootpath == tmp_path / "myproject"
 | 
				
			||||||
 | 
					        assert inipath == tmp_path / "myproject" / "setup.cfg"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TestOverrideIniArgs:
 | 
					class TestOverrideIniArgs:
 | 
				
			||||||
    @pytest.mark.parametrize("name", "setup.cfg tox.ini pytest.ini".split())
 | 
					    @pytest.mark.parametrize("name", "setup.cfg tox.ini pytest.ini".split())
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue