rDrama/run_tests.py

53 lines
1.0 KiB
Python
Raw Normal View History

2022-05-17 21:09:36 +00:00
#!/usr/bin/python3
import subprocess
import sys
# we want to leave the container in whatever state it currently is, so check to see if it's running
docker_inspect = subprocess.run([
2022-06-13 18:33:25 +00:00
"docker",
"container",
"inspect",
"-f", "{{.State.Status}}",
"rDrama",
],
capture_output = True,
).stdout.decode("utf-8").strip()
2022-05-17 21:09:36 +00:00
was_running = docker_inspect == "running"
# update containers, just in case they're out of date
if was_running:
2022-06-13 18:33:25 +00:00
print("Updating containers . . .", flush=True)
2022-05-17 21:09:36 +00:00
else:
2022-06-13 18:33:25 +00:00
print("Starting containers . . .", flush=True)
2022-05-17 21:09:36 +00:00
subprocess.run([
2022-06-13 18:33:25 +00:00
"docker-compose",
"up",
"--build",
"-d",
],
check = True,
)
2022-05-17 21:09:36 +00:00
# run the test
2022-05-22 22:45:04 +00:00
print("Running test . . .", flush=True)
2022-05-17 21:09:36 +00:00
result = subprocess.run([
2022-06-13 18:33:25 +00:00
"docker",
"exec",
"rDrama",
"bash", "-c", "cd service && python3 -m pytest -s"
])
2022-05-17 21:09:36 +00:00
if not was_running:
2022-06-13 18:33:25 +00:00
# shut down, if we weren't running in the first place
print("Shutting down containers . . .", flush=True)
subprocess.run([
"docker-compose",
"stop",
],
check = True,
)
2022-05-17 21:09:36 +00:00
2022-06-13 18:33:25 +00:00
sys.exit(result.returncode)