-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathconftest.py
More file actions
68 lines (48 loc) · 1.82 KB
/
Copy pathconftest.py
File metadata and controls
68 lines (48 loc) · 1.82 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
import logging
import random
import time
from multiprocessing import Manager
import pytest
from testcontainers.keycloak import KeycloakContainer
from testcontainers.minio import MinioContainer
from testcontainers.mysql import MySqlContainer
from testcontainers.postgres import PostgresContainer
from tests.utils.auth_permissions_util import setup_permissions_on_keycloak
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
shared_state = Manager().dict()
@pytest.fixture(scope="session")
def start_keycloak_server():
# Add random sleep between 0 and 2 before checking the state to avoid concurrency issues.
random_sleep_time = random.uniform(0, 2)
time.sleep(random_sleep_time)
# If the Keycloak instance is already started (in any worker), reuse it
if shared_state.get("keycloak_started", False):
return shared_state["keycloak_url"]
logger.info("Starting keycloak instance")
with KeycloakContainer("quay.io/keycloak/keycloak:24.0.1") as keycloak_container:
setup_permissions_on_keycloak(keycloak_container.get_client())
shared_state["keycloak_started"] = True
shared_state["keycloak_url"] = keycloak_container.get_url()
yield shared_state["keycloak_url"]
# After the fixture is done, cleanup the shared state
del shared_state["keycloak_started"]
del shared_state["keycloak_url"]
@pytest.fixture(scope="session")
def mysql_server():
container = MySqlContainer("mysql:latest")
container.start()
yield container
container.stop()
@pytest.fixture(scope="session")
def postgres_server():
container = PostgresContainer()
container.start()
yield container
container.stop()
@pytest.fixture(scope="session")
def minio_server():
container = MinioContainer()
container.start()
yield container
container.stop()