mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-23 22:06:28 +01: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 __future__ import annotations
|
||||||
|
|
||||||
from pathlib import PurePosixPath
|
from pathlib import Path, PurePosixPath
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
@ -73,9 +73,27 @@ def main() -> int:
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
packages = _affected_packages(files)
|
packages = _affected_packages(files)
|
||||||
cmd = _build_pytest_command(packages)
|
|
||||||
result = subprocess.run(cmd, check=False)
|
# When many packages are affected, run each one in a separate subprocess
|
||||||
return result.returncode
|
# 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__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user