Spaces:
Paused
Paused
| 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()) |