Files
mtusi2026lab2-fork/student-tests/run_all.py

44 lines
1.8 KiB
Python

"""Запуск собственных тестов.
python student-tests/run_all.py --base-url http://127.0.0.1:8080
# + истечение сессии на экземпляре с коротким TTL:
python student-tests/run_all.py --expiry-url http://127.0.0.1:8081
# + отказ Redis/PostgreSQL (останавливает контейнеры!):
python student-tests/run_all.py --expiry-url http://127.0.0.1:8081 --with-failures
"""
import argparse
import os
import subprocess
import sys
parser = argparse.ArgumentParser()
parser.add_argument("--base-url", default="http://127.0.0.1:8080")
parser.add_argument("--expiry-url", default=os.environ.get("EXPIRY_BASE_URL", ""))
parser.add_argument("--with-failures", action="store_true",
help="run student-tests/dependency_failure.py (stops redis/postgres)")
parser.add_argument("--failure-args", default="",
help="extra arguments for dependency_failure.py (custom stop/start commands)")
args = parser.parse_args()
env = os.environ.copy()
env["BASE_URL"] = args.base_url.rstrip("/")
if args.expiry_url:
env["EXPIRY_BASE_URL"] = args.expiry_url.rstrip("/")
def step(title, cmd):
print("\n== " + title, flush=True)
subprocess.run(cmd, env=env, check=True)
step("API, auth, concurrency, rollback, expiry tests",
[sys.executable, "-m", "unittest", "discover", "-s", "student-tests", "-p", "test_*.py", "-v"])
step("Concurrent write test", [sys.executable, "student-tests/race.py", "--base-url", args.base_url])
if args.with_failures:
import shlex
step("Dependency failure scenario",
[sys.executable, "student-tests/dependency_failure.py", "--base-url", args.base_url]
+ shlex.split(args.failure_args))
print("\nALL STUDENT TESTS PASSED", flush=True)