Skip to content

Commit e262704

Browse files
author
Aditya Mehra
committed
Add regression test for issue #13822
- Test verifies that setup.py in system temp dir is ignored - Uses monkeypatch to simulate /tmp/setup.py without touching system - Ensures rootdir detection works correctly
1 parent d5032d5 commit e262704

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

testing/test_config.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1830,6 +1830,42 @@ def test_with_config_also_in_parent_directory(
18301830
assert rootpath == tmp_path / "myproject"
18311831
assert inipath == tmp_path / "myproject" / "setup.cfg"
18321832

1833+
def test_tmp_setup_py_does_not_affect_rootdir(
1834+
self, tmp_path: Path, monkeypatch: MonkeyPatch
1835+
) -> None:
1836+
"""Regression test for issue #13822.
1837+
1838+
Ensure that setup.py in the system temp directory doesn't
1839+
affect rootdir detection.
1840+
"""
1841+
# Create a fake project structure
1842+
project = tmp_path / "my_project"
1843+
project.mkdir()
1844+
test_dir = project / "tests"
1845+
test_dir.mkdir()
1846+
1847+
# Create project's own setup.py
1848+
(project / "setup.py").write_text("# project setup", "utf-8")
1849+
1850+
# Monkeypatch tempfile.gettempdir() to simulate /tmp/setup.py existing
1851+
fake_temp = tmp_path / "fake_tmp"
1852+
fake_temp.mkdir()
1853+
(fake_temp / "setup.py").write_text("# tmp setup", "utf-8")
1854+
1855+
monkeypatch.setattr("tempfile.gettempdir", lambda: str(fake_temp))
1856+
monkeypatch.chdir(test_dir)
1857+
1858+
rootpath, inipath, *_ = determine_setup(
1859+
inifile=None,
1860+
args=[str(test_dir)],
1861+
rootdir_cmd_arg=None,
1862+
invocation_dir=test_dir,
1863+
)
1864+
1865+
# Rootpath should be project, not fake temp
1866+
assert rootpath == project
1867+
assert rootpath != fake_temp
1868+
18331869

18341870
class TestOverrideIniArgs:
18351871
@pytest.mark.parametrize("name", "setup.cfg tox.ini pytest.ini".split())

0 commit comments

Comments
 (0)