File size: 1,481 Bytes
b70ff07
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import os
import sys
import subprocess
import time

def run_tests():
    # Set up environment variables
    os.environ["TEST_ENV"] = "prod"
    os.environ["PYTHONPATH"] = os.path.dirname(os.path.abspath(__file__))
    os.environ["PROD_API_URL"] = "https://fred808-admin-desk.hf.space"
    
    # Add retry mechanism for API availability
    max_retries = 3
    retry_delay = 5  # seconds
    
    for attempt in range(max_retries):
        # Run pytest with verbose flag and proper output capture
        cmd = [
            "python", "-m", "pytest",
            "-v",
            "--capture=no",
            "--asyncio-mode=auto",  # Better async handling
            "tests/api/test_auth.py"
        ]
        
        process = subprocess.run(cmd, text=True, capture_output=True)
        
        # Print output
        print(f"\nAttempt {attempt + 1} of {max_retries}")
        print("\nTest Output:")
        print(process.stdout)
        
        if process.stderr:
            print("\nErrors:")
            print(process.stderr)
        
        # Check if tests failed due to service unavailable
        if "503 Service Unavailable" not in process.stdout:
            return process.returncode
            
        print(f"\nService unavailable, retrying in {retry_delay} seconds...")
        time.sleep(retry_delay)
    
    return 1  # Return error if all retries failed

if __name__ == "__main__":
    sys.exit(run_tests())