-
Notifications
You must be signed in to change notification settings - Fork 0
/
conftest.py
43 lines (33 loc) · 1.11 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
import warnings
import pytest
from unittest.mock import patch
from sqlmodel import create_engine
from dundie import models
from sqlalchemy.exc import SAWarning
warnings.filterwarnings("ignore", category=SAWarning)
MARKER = """\
unit: Mark unit tests
integration: Mark integration tests
high: High Priority
medium: Medium Priority
low: Low Priority
"""
def pytest_configure(config):
for line in MARKER.split("\n"):
config.addinivalue_line("markers", line)
@pytest.fixture(autouse=True)
def go_to_tmpdir(request): # injeção de dependencias
tmpdir = request.getfixturevalue("tmpdir")
with tmpdir.as_cwd():
yield # protocolo de generators
@pytest.fixture(autouse=True, scope="function")
def setup_testing_database(request):
"""For each test, create a database file on tmpdir
force database.py to use that filepath.
"""
tmpdir = request.getfixturevalue("tmpdir")
test_db = str(tmpdir.join("database.test.db"))
engine = create_engine(f"sqlite:///{test_db}")
models.SQLModel.metadata.create_all(bind=engine)
with patch("dundie.database.engine", engine):
yield