[tests] Build tests from the tree they run in, not the venv's editable install (#18248)

Co-authored-by: Jonathan Swoboda <154711427+swoboda1337@users.noreply.github.com>
This commit is contained in:
Bonne Eggleston
2026-08-11 19:09:51 -04:00
committed by GitHub
co-authored by Jonathan Swoboda
parent e0b112c584
commit 3540012529
2 changed files with 11 additions and 1 deletions
+3
View File
@@ -56,6 +56,9 @@ include = ["esphome*"]
testpaths = [
"tests",
]
# Prepend the repo root so in-process esphome imports resolve to THIS tree,
# not wherever the venv's editable install points (e.g. another git worktree).
pythonpath = ["."]
addopts = [
"--cov=esphome",
"--cov-branch",
+8 -1
View File
@@ -63,6 +63,11 @@ def _get_platformio_env(cache_dir: Path) -> dict[str, str]:
env["PLATFORMIO_LIBDEPS_DIR"] = str(cache_dir / "libdeps")
# Prevent cache cleaning during integration tests
env["ESPHOME_SKIP_CLEAN_BUILD"] = "1"
# Compile with THIS tree's esphome sources, not wherever the venv's editable
# install points (which may be a different git worktree or checkout).
repo_root = str(Path(__file__).resolve().parent.parent.parent)
existing = env.get("PYTHONPATH")
env["PYTHONPATH"] = f"{repo_root}{os.pathsep}{existing}" if existing else repo_root
return env
@@ -101,7 +106,7 @@ def shared_platformio_cache() -> Generator[Path]:
env = _get_platformio_env(cache_dir)
subprocess.run(
["esphome", "compile", str(config_path)],
[sys.executable, "-m", "esphome", "compile", str(config_path)],
check=True,
cwd=init_dir,
env=env,
@@ -245,6 +250,8 @@ async def compile_esphome(
for attempt in range(max_retries):
# Compile using subprocess, inheriting stdout/stderr to show progress
proc = await asyncio.create_subprocess_exec(
sys.executable,
"-m",
"esphome",
"compile",
str(config_path),