Search in the list of arguments for a valid ini-file for pytest, and return a tuple of (rootdir, inifile, cfg-dict).
(
args: Iterable[Path],
)
| 86 | |
| 87 | |
| 88 | def locate_config( |
| 89 | args: Iterable[Path], |
| 90 | ) -> Tuple[Optional[Path], Optional[Path], Dict[str, Union[str, List[str]]]]: |
| 91 | """Search in the list of arguments for a valid ini-file for pytest, |
| 92 | and return a tuple of (rootdir, inifile, cfg-dict).""" |
| 93 | config_names = [ |
| 94 | "pytest.ini", |
| 95 | "pyproject.toml", |
| 96 | "tox.ini", |
| 97 | "setup.cfg", |
| 98 | ] |
| 99 | args = [x for x in args if not str(x).startswith("-")] |
| 100 | if not args: |
| 101 | args = [Path.cwd()] |
| 102 | for arg in args: |
| 103 | argpath = absolutepath(arg) |
| 104 | for base in (argpath, *argpath.parents): |
| 105 | for config_name in config_names: |
| 106 | p = base / config_name |
| 107 | if p.is_file(): |
| 108 | ini_config = load_config_dict_from_file(p) |
| 109 | if ini_config is not None: |
| 110 | return base, p, ini_config |
| 111 | return None, None, {} |
| 112 | |
| 113 | |
| 114 | def get_common_ancestor(paths: Iterable[Path]) -> Path: |