Skip to content

Commit cc400d1

Browse files
committed
config: consider empty .pytest.ini as config file
Fix #13849.
1 parent 18fbe17 commit cc400d1

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

changelog/13849.bugfix.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Hidden ``.pytest.ini`` files are now picked up as the config file even if empty.
2+
This was an inconsistency with non-hidden ``pytest.ini``.

src/_pytest/config/findpaths.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def load_config_dict_from_file(
6868
}
6969
else:
7070
# "pytest.ini" files are always the source of configuration, even if empty.
71-
if filepath.name == "pytest.ini":
71+
if filepath.name in {"pytest.ini", ".pytest.ini"}:
7272
return {}
7373

7474
# '.cfg' files are considered if they contain a "[tool:pytest]" section.

testing/test_config.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1826,13 +1826,16 @@ def test_with_ini(self, tmp_path: Path, name: str, contents: str) -> None:
18261826
assert parsed_inipath == inipath
18271827
assert ini_config["x"] == ConfigValue("10", origin="file")
18281828

1829-
@pytest.mark.parametrize("name", ["setup.cfg", "tox.ini"])
1830-
def test_pytestini_overrides_empty_other(self, tmp_path: Path, name: str) -> None:
1831-
inipath = tmp_path / "pytest.ini"
1829+
@pytest.mark.parametrize("pytest_ini", ["pytest.ini", ".pytest.ini"])
1830+
@pytest.mark.parametrize("other", ["setup.cfg", "tox.ini"])
1831+
def test_pytestini_overrides_empty_other(
1832+
self, tmp_path: Path, pytest_ini: str, other: str
1833+
) -> None:
1834+
inipath = tmp_path / pytest_ini
18321835
inipath.touch()
18331836
a = tmp_path / "a"
18341837
a.mkdir()
1835-
(a / name).touch()
1838+
(a / other).touch()
18361839
rootpath, parsed_inipath, *_ = determine_setup(
18371840
inifile=None,
18381841
override_ini=None,

testing/test_findpaths.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515

1616

1717
class TestLoadConfigDictFromFile:
18-
def test_empty_pytest_ini(self, tmp_path: Path) -> None:
18+
@pytest.mark.parametrize("filename", ["pytest.ini", ".pytest.ini"])
19+
def test_empty_pytest_ini(self, tmp_path: Path, filename: str) -> None:
1920
"""pytest.ini files are always considered for configuration, even if empty"""
20-
fn = tmp_path / "pytest.ini"
21+
fn = tmp_path / filename
2122
fn.write_text("", encoding="utf-8")
2223
assert load_config_dict_from_file(fn) == {}
2324

0 commit comments

Comments
 (0)