[ty] Improve resolution of absolute imports in tests (#21817)

By teaching desperate resolution to try every possible ancestor that
doesn't have an `__init__.py(i)` when resolving absolute imports.

* Fixes https://github.com/astral-sh/ty/issues/1782
This commit is contained in:
Aria Desires
2025-12-12 11:59:06 -05:00
committed by GitHub
parent 3ac58b47bd
commit d5546508cf
4 changed files with 174 additions and 61 deletions

View File

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