Files
2026-06-16 17:37:16 +08:00

41 lines
1017 B
Python

"""Run pytest under coverage in this environment.
The plain ``coverage run -m pytest`` path reloads NumPy under the current VS Code
Python startup environment, which breaks pandas/numpy reductions. Import NumPy
before starting coverage so the measured test run uses one stable NumPy module.
"""
from __future__ import annotations
import sys
import numpy # noqa: F401
import coverage
import pytest
def main(argv: list[str]) -> int:
pytest_args = argv or ["tests/", "-v"]
cov = coverage.Coverage(config_file=True)
cov.erase()
cov.start()
test_status = pytest.main(pytest_args)
cov.stop()
cov.save()
if test_status != 0:
return int(test_status)
total = cov.report()
print(f"\nCoverage total: {total:.2f}%")
fail_under = float(cov.config.fail_under)
if total < fail_under:
print(f"Coverage failure: total {total:.2f}% is below {fail_under:.2f}%")
return 2
return 0
if __name__ == "__main__":
raise SystemExit(main(sys.argv[1:]))