2022-10-29 23:26:28 +08:00
|
|
|
import unittest
|
|
|
|
import requests
|
|
|
|
import time
|
2023-03-11 13:27:10 +08:00
|
|
|
import os
|
|
|
|
from modules.paths import script_path
|
2022-10-29 23:26:28 +08:00
|
|
|
|
2022-10-30 13:22:44 +08:00
|
|
|
|
2022-11-14 18:39:22 +08:00
|
|
|
def run_tests(proc, test_dir):
|
2022-10-30 13:22:44 +08:00
|
|
|
timeout_threshold = 240
|
|
|
|
start_time = time.time()
|
|
|
|
while time.time()-start_time < timeout_threshold:
|
|
|
|
try:
|
2022-11-14 23:40:15 +08:00
|
|
|
requests.head("http://localhost:7860/")
|
2022-10-30 13:22:44 +08:00
|
|
|
break
|
|
|
|
except requests.exceptions.ConnectionError:
|
2022-11-12 20:12:15 +08:00
|
|
|
if proc.poll() is not None:
|
|
|
|
break
|
|
|
|
if proc.poll() is None:
|
2022-11-14 18:39:22 +08:00
|
|
|
if test_dir is None:
|
2023-03-11 13:27:10 +08:00
|
|
|
test_dir = os.path.join(script_path, "test")
|
|
|
|
suite = unittest.TestLoader().discover(test_dir, pattern="*_test.py", top_level_dir=test_dir)
|
2022-10-30 13:22:44 +08:00
|
|
|
result = unittest.TextTestRunner(verbosity=2).run(suite)
|
2022-11-14 19:55:39 +08:00
|
|
|
return len(result.failures) + len(result.errors)
|
2022-10-30 13:22:44 +08:00
|
|
|
else:
|
|
|
|
print("Launch unsuccessful")
|
2022-11-14 19:36:07 +08:00
|
|
|
return 1
|