@@ -62,3 +62,39 @@ def test_multiple_namespace_packages(self, tmp_path: Path):
6262
6363 with change_cwd (tmp_path ):
6464 assert get_importable_packages () == {"foo" , "bar" }
65+
66+ def test_flat_layout_excludes_root_py_files (self , tmp_path : Path ):
67+ """Test that root-level .py files are excluded in a flat layout.
68+
69+ In a flat layout (no src/ directory), standalone .py files like
70+ setup.py or conftest.py should not be detected as importable packages.
71+ Only directories with __init__.py should be included.
72+ """
73+ (tmp_path / "foo" ).mkdir ()
74+ (tmp_path / "foo" / "__init__.py" ).touch ()
75+ (tmp_path / "foo" / "bar.py" ).touch ()
76+ # Root-level .py files that should be excluded
77+ (tmp_path / "setup.py" ).touch ()
78+ (tmp_path / "conftest.py" ).touch ()
79+
80+ with change_cwd (tmp_path ):
81+ # Should only include "foo" package, not "setup" or "conftest" modules
82+ assert get_importable_packages () == {"foo" }
83+
84+ def test_src_layout_excludes_root_py_files (self , tmp_path : Path ):
85+ """Test that root-level .py files are excluded in a src/ layout.
86+
87+ In a src/ layout, standalone .py files in src/ like __init__.py
88+ (without a package directory) should not be detected as importable packages.
89+ """
90+ (tmp_path / "src" ).mkdir ()
91+ (tmp_path / "src" / "foo" ).mkdir ()
92+ (tmp_path / "src" / "foo" / "__init__.py" ).touch ()
93+ (tmp_path / "src" / "foo" / "bar.py" ).touch ()
94+ # Root-level .py files in src/ that should be excluded
95+ (tmp_path / "src" / "conftest.py" ).touch ()
96+ (tmp_path / "src" / "helper.py" ).touch ()
97+
98+ with change_cwd (tmp_path ):
99+ # Should only include "foo" package, not "conftest" or "helper" modules
100+ assert get_importable_packages () == {"foo" }
0 commit comments