full freedom

This commit is contained in:
Aria Desires 2025-12-12 08:09:51 -05:00
parent 28e9c9aecb
commit e16ab3efa7
2 changed files with 12 additions and 7 deletions

View File

@ -2390,14 +2390,14 @@ fn default_root_flat_layout() -> anyhow::Result<()> {
fn default_root_tests_folder() -> anyhow::Result<()> { fn default_root_tests_folder() -> anyhow::Result<()> {
let case = CliTest::with_files([ let case = CliTest::with_files([
("src/foo.py", "foo = 10"), ("src/foo.py", "foo = 10"),
("tests/bar.py", "bar = 20"), ("tests/bar.py", "baz = 20"),
( (
"tests/test_bar.py", "tests/test_bar.py",
r#" r#"
from foo import foo from foo import foo
from bar import bar from bar import baz
print(f"{foo} {bar}") print(f"{foo} {baz}")
"#, "#,
), ),
])?; ])?;

View File

@ -432,12 +432,17 @@ fn desperate_search_paths(db: &dyn Db, importing_file: File) -> Option<Vec<Searc
let mut search_paths = Vec::new(); let mut search_paths = Vec::new();
for rel_dir in rel_path.ancestors() { for rel_dir in rel_path.ancestors() {
let candidate_path = base_path.join(rel_dir); let candidate_path = base_path.join(rel_dir);
// Any dir named `tests` might be a pytest root, but not if it's a package if !system.is_directory(&candidate_path) {
let is_pytest_dir = rel_dir.file_name() == Some("tests") continue;
&& !system.is_file(&candidate_path.join("__init__.py")) }
// Any dir that isn't a proper package is plausibly some test/script dir that could be
// added as a search-path at runtime. Notably this reflects pytest's default mode where
// it adds every dir with a .py to the search-paths (making all test files root modules),
// unless they see an `__init__.py`, in which case they assume you don't want that.
let isnt_regular_package = !system.is_file(&candidate_path.join("__init__.py"))
&& !system.is_file(&candidate_path.join("__init__.pyi")); && !system.is_file(&candidate_path.join("__init__.pyi"));
// Any dir with a pyproject.toml or ty.toml might be a project root // Any dir with a pyproject.toml or ty.toml might be a project root
if is_pytest_dir if isnt_regular_package
|| system.is_file(&candidate_path.join("pyproject.toml")) || system.is_file(&candidate_path.join("pyproject.toml"))
|| system.is_file(&candidate_path.join("ty.toml")) || system.is_file(&candidate_path.join("ty.toml"))
{ {