-
-
Notifications
You must be signed in to change notification settings - Fork 280
Expand file tree
/
Copy pathconftest.py
More file actions
33 lines (26 loc) · 914 Bytes
/
conftest.py
File metadata and controls
33 lines (26 loc) · 914 Bytes
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
from textwrap import dedent
import pytest
from pytest import FixtureRequest
from sqlalchemy.engine import Engine, create_engine
from sqlalchemy.orm import clear_mappers, configure_mappers
from sqlalchemy.schema import MetaData
@pytest.fixture
def engine(request: FixtureRequest) -> Engine:
dialect = getattr(request, "param", None)
if dialect == "postgresql":
return create_engine("postgresql+psycopg:///testdb")
elif dialect == "mysql":
return create_engine("mysql+mysqlconnector://testdb")
else:
return create_engine("sqlite:///:memory:")
@pytest.fixture
def metadata() -> MetaData:
return MetaData()
def validate_code(generated_code: str, expected_code: str) -> None:
expected_code = dedent(expected_code)
assert generated_code == expected_code
try:
exec(generated_code, {})
configure_mappers()
finally:
clear_mappers()