-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path152.py
More file actions
71 lines (60 loc) · 1.86 KB
/
Copy path152.py
File metadata and controls
71 lines (60 loc) · 1.86 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import subprocess
import sys
import time
def wait_for_postgres(max_retries=5, delay=5):
for _ in range(max_retries):
try:
result = subprocess.run(
[
"docker",
"compose",
"-f",
"docker-compose.test.yaml",
"exec",
"postgres-test",
"pg_isready",
"-U",
"postgres",
"-d",
"postgres",
],
check=True,
capture_output=True,
text=True,
)
if "accepting connections" in result.stdout:
print("PostgreSQL is ready.")
return True
except subprocess.CalledProcessError:
print(f"PostgreSQL is not ready yet. Retrying in {delay} seconds...")
time.sleep(delay)
print("Failed to connect to PostgreSQL.")
return False
def run_command(command, check=True):
try:
subprocess.run(command, check=check)
except subprocess.CalledProcessError as e:
print(f"Command failed: {e}")
sys.exit(1)
def test():
# Start PostgreSQL with Docker Compose
run_command(
[
"docker",
"compose",
"-f",
"docker-compose.test.yaml",
"up",
"-d",
"postgres-test",
]
)
if not wait_for_postgres():
run_command(["docker", "compose", "-f", "docker-compose.test.yaml", "down"])
sys.exit(1)
# Run Prisma migrations
run_command(["prisma", "migrate", "dev"])
# Run the tests
result = subprocess.run(["pytest"] + sys.argv[1:], check=False)
run_command(["docker", "compose", "-f", "docker-compose.test.yaml", "down"])
sys.exit(result.returncode)