-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
48 lines (38 loc) · 1.47 KB
/
conftest.py
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
import pytest
from retry import retry
from exceptions import UnhealthyContainerException, HealthCheckFailedException
from consts import *
pytest_plugins = ["docker_compose"]
@retry(HealthCheckFailedException, delay=HEALTH_CHECKS_DELAY_SECS)
def wait_until_healthy(container):
health_status = container.inspect()["State"]["Health"]["Status"]
if health_status == "unhealthy":
raise UnhealthyContainerException("Service is unhealthy")
if not health_status == "healthy":
raise HealthCheckFailedException()
def get_container_default_network_ip(container):
default_network = container.project + "_default"
networks = container.inspect()["NetworkSettings"]["Networks"]
return networks[default_network]["IPAddress"]
@pytest.fixture(scope="session")
def sql_server_service(request, docker_project, session_scoped_container_getter):
container = session_scoped_container_getter.get("mysql-server")
container_ip_address = get_container_default_network_ip(container)
wait_until_healthy(container)
return (container_ip_address,)
# Service configuration example
# import egg_shooter
#
#
# @pytest_fixture(scope="session")
# def egg_shooter_service():
# service_container = session_scoped_container_getter.get("egg_shooter")
# wait_until_healthy(service)
#
# egg_shooter.configuration = EggShooterConfiguration(
# ip = get_container_default_network_ip(service_container)
# )
#
# yield
#
# # Tear down (such as removing files)