mirror of
https://github.com/fastapi/sqlmodel.git
synced 2026-02-04 11:44:01 +08:00
✅ Simplify tests for code examples, one test file for multiple variants (#1664)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
@@ -1,11 +1,27 @@
|
||||
import importlib
|
||||
from types import ModuleType
|
||||
|
||||
import pytest
|
||||
from sqlmodel import Session, create_engine, select
|
||||
|
||||
from ...conftest import needs_py310
|
||||
|
||||
def test_tutorial(clear_sqlmodel):
|
||||
from docs_src.tutorial.insert import tutorial002 as mod
|
||||
|
||||
@pytest.fixture(
|
||||
name="mod",
|
||||
params=[
|
||||
"tutorial002",
|
||||
pytest.param("tutorial002_py310", marks=needs_py310),
|
||||
],
|
||||
)
|
||||
def get_module(request: pytest.FixtureRequest) -> ModuleType:
|
||||
mod = importlib.import_module(f"docs_src.tutorial.insert.{request.param}")
|
||||
mod.sqlite_url = "sqlite://"
|
||||
mod.engine = create_engine(mod.sqlite_url)
|
||||
return mod
|
||||
|
||||
|
||||
def test_tutorial(mod: ModuleType):
|
||||
mod.main()
|
||||
with Session(mod.engine) as session:
|
||||
heroes = session.exec(select(mod.Hero)).all()
|
||||
|
||||
Reference in New Issue
Block a user