mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-07-04 14:43:01 +02:00
Fix pytest OOM: run packages sequentially in separate subprocesses
Each python_pkg subpackage now runs in its own pytest subprocess so memory is freed between packages. Prevents 4GB+ accumulation when matplotlib, geopandas, pygame, etc. all load in a single process.
This commit is contained in:
parent
c2f1f0d9f8
commit
030741c315
@ -11,7 +11,7 @@ all tests are run as a fallback.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import PurePosixPath
|
||||
from pathlib import Path, PurePosixPath
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
@ -73,9 +73,27 @@ def main() -> int:
|
||||
return 0
|
||||
|
||||
packages = _affected_packages(files)
|
||||
cmd = _build_pytest_command(packages)
|
||||
result = subprocess.run(cmd, check=False)
|
||||
return result.returncode
|
||||
|
||||
# When many packages are affected, run each one in a separate subprocess
|
||||
# to avoid accumulating memory across all test suites (OOM prevention).
|
||||
if packages is None:
|
||||
# Discover all subpackages that have a tests/ directory.
|
||||
packages = {
|
||||
entry.name
|
||||
for entry in Path("python_pkg").iterdir()
|
||||
if (entry / "tests").is_dir()
|
||||
}
|
||||
|
||||
if not packages:
|
||||
return 0
|
||||
|
||||
# Run each package in its own subprocess so memory is freed between runs.
|
||||
for pkg in sorted(packages):
|
||||
cmd = _build_pytest_command({pkg})
|
||||
result = subprocess.run(cmd, check=False)
|
||||
if result.returncode != 0:
|
||||
return result.returncode
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Loading…
Reference in New Issue
Block a user