Skip to content

Commit 28cb1cc

Browse files
committed
Simplify tests for docs_src.advanced.uuid.tutorial002*
1 parent 1962d72 commit 28cb1cc

File tree

2 files changed

+19
-84
lines changed

2 files changed

+19
-84
lines changed

tests/test_advanced/test_uuid/test_tutorial002.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,38 @@
1-
from unittest.mock import patch
1+
import importlib
2+
from types import ModuleType
23

4+
import pytest
35
from dirty_equals import IsUUID
46
from sqlmodel import create_engine
57

6-
from ...conftest import get_testing_print_function
8+
from ...conftest import PrintMock, needs_py310
79

810

9-
def test_tutorial() -> None:
10-
from docs_src.advanced.uuid import tutorial002 as mod
11-
11+
@pytest.fixture(
12+
name="mod",
13+
params=[
14+
"tutorial002",
15+
pytest.param("tutorial002_py310", marks=needs_py310),
16+
],
17+
)
18+
def get_module(request: pytest.FixtureRequest) -> ModuleType:
19+
mod = importlib.import_module(f"docs_src.advanced.uuid.{request.param}")
1220
mod.sqlite_url = "sqlite://"
1321
mod.engine = create_engine(mod.sqlite_url)
14-
calls = []
22+
return mod
1523

16-
new_print = get_testing_print_function(calls)
1724

18-
with patch("builtins.print", new=new_print):
19-
mod.main()
20-
first_uuid = calls[1][0]["id"]
25+
def test_tutorial(print_mock: PrintMock, mod: ModuleType) -> None:
26+
mod.main()
27+
first_uuid = print_mock.calls[1][0]["id"]
2128
assert first_uuid == IsUUID(4)
2229

23-
second_uuid = calls[7][0]["id"]
30+
second_uuid = print_mock.calls[7][0]["id"]
2431
assert second_uuid == IsUUID(4)
2532

2633
assert first_uuid != second_uuid
2734

28-
assert calls == [
35+
assert print_mock.calls == [
2936
["The hero before saving in the DB"],
3037
[
3138
{

tests/test_advanced/test_uuid/test_tutorial002_py310.py

Lines changed: 0 additions & 72 deletions
This file was deleted.

0 commit comments

Comments
 (0)