Skip to content

Commit c657fa1

Browse files
authored
chore: test sqla_modules fixture (#19)
1 parent 2c7b885 commit c657fa1

2 files changed

Lines changed: 45 additions & 1 deletion

File tree

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from sqlalchemy import engine_from_config
66
from sqlalchemy.orm.session import close_all_sessions
77

8-
pytest_plugins = ["fastapi_sqla._pytest_plugin"]
8+
pytest_plugins = ["fastapi_sqla._pytest_plugin", "pytester"]
99

1010

1111
@fixture(scope="session", autouse=True)

tests/test_pytest_plugin.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,47 @@ def test_all_opened_sessions_are_within_the_same_transaction(session, singer_cls
4545

4646
other_session = _Session()
4747
assert other_session.query(singer_cls).get(1)
48+
49+
50+
@fixture
51+
def conftest(db_url, testdir):
52+
testdir.makeconftest(
53+
f"""
54+
from pytest import fixture
55+
56+
@fixture(scope="session")
57+
def db_url():
58+
return "{db_url}"
59+
"""
60+
)
61+
62+
63+
def test_sqla_modules(testdir, conftest):
64+
testdir.makepyfile(
65+
"""
66+
from pytest import fixture
67+
68+
69+
@fixture
70+
def sqla_modules():
71+
pass
72+
73+
74+
def test_anything(session):
75+
session.execute("SELECT 1")
76+
"""
77+
)
78+
result = testdir.runpytest()
79+
result.assert_outcomes(passed=1)
80+
81+
82+
def test_sqla_modules_fixture_raises_exception_when_not_overriden(testdir, conftest):
83+
testdir.makepyfile(
84+
"""
85+
def test_anything(session):
86+
session.execute("SELECT 1")
87+
"""
88+
)
89+
result = testdir.runpytest()
90+
result.assert_outcomes(errors=1)
91+
result.stdout.fnmatch_lines(["*sqla_modules fixture is not defined*"])

0 commit comments

Comments
 (0)