-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
84 lines (61 loc) · 2.15 KB
/
conftest.py
File metadata and controls
84 lines (61 loc) · 2.15 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
72
73
74
75
76
77
78
79
80
81
82
83
84
import pytest
import time
from sqlalchemy import Boolean, Identity, String
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
# Testcontainer image versions
POSTGRES_IMAGE = "postgres:latest"
MYSQL_IMAGE = "mysql:latest"
MONGODB_IMAGE = "mongo:8.0"
MARIADB_IMAGE = "mariadb:latest"
ORACLE_IMAGE = "gvenzl/oracle-free:slim-faststart"
MSSQL_IMAGE = "mcr.microsoft.com/mssql/server:2022-latest"
class Base(DeclarativeBase):
pass
class IntegrationModel(Base):
__tablename__ = "integration_test"
id: Mapped[int] = mapped_column(Identity(always=True), primary_key=True)
name: Mapped[str] = mapped_column(String(255), nullable=True)
enabled: Mapped[bool] = mapped_column(Boolean, default=True)
@pytest.fixture(scope="session")
def postgres_container():
from testcontainers.postgres import PostgresContainer
with PostgresContainer(POSTGRES_IMAGE) as pg:
yield pg
@pytest.fixture(scope="session")
def mysql_container():
from testcontainers.mysql import MySqlContainer
with MySqlContainer(MYSQL_IMAGE) as mysql:
yield mysql
@pytest.fixture(scope="session")
def mssql_container():
from testcontainers.mssql import SqlServerContainer
with SqlServerContainer(MSSQL_IMAGE, password="Strong@Pass123") as mssql:
yield mssql
@pytest.fixture(scope="session")
def mongodb_container():
from testcontainers.mongodb import MongoDbContainer
max_attempts = 3
last_exc = None
for attempt in range(max_attempts):
try:
container = MongoDbContainer(MONGODB_IMAGE)
container.start()
break
except Exception as exc:
last_exc = exc
if attempt < max_attempts - 1:
time.sleep(2)
else:
raise last_exc
yield container
container.stop()
@pytest.fixture(scope="session")
def mariadb_container():
from testcontainers.mysql import MySqlContainer
with MySqlContainer(MARIADB_IMAGE) as mariadb:
yield mariadb
@pytest.fixture(scope="session")
def oracle_container():
from testcontainers.oracle import OracleDbContainer
with OracleDbContainer(ORACLE_IMAGE) as oracle:
yield oracle