File size: 758 Bytes
ae26e7d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import unittest
import requests
import time


def run_tests(proc, test_dir):
    timeout_threshold = 240
    start_time = time.time()
    while time.time()-start_time < timeout_threshold:
        try:
            requests.head("http://localhost:7860/")
            break
        except requests.exceptions.ConnectionError:
            if proc.poll() is not None:
                break
    if proc.poll() is None:
        if test_dir is None:
            test_dir = "test"
        suite = unittest.TestLoader().discover(test_dir, pattern="*_test.py", top_level_dir="test")
        result = unittest.TextTestRunner(verbosity=2).run(suite)
        return len(result.failures) + len(result.errors)
    else:
        print("Launch unsuccessful")
        return 1