FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

✅ Simplify tests for `tests/test_tutorial/test_code_structure/test_tutorial001.py`, one test file for multiple variants by tiangolo · Pull Request #1408 · fastapi/sqlmodel · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (3) All 1 file type selected
Deleted files Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from unittest.mock import patch
import importlib
from dataclasses import dataclass
from types import ModuleType

import pytest
from sqlmodel import create_engine

from ...conftest import get_testing_print_function
from tests.conftest import PrintMock, needs_py39, needs_py310

expected_calls = [
[
Expand All @@ -22,16 +25,34 @@
]


def test_tutorial():
from docs_src.tutorial.code_structure.tutorial001 import app, database
@dataclass
class Modules:
app: ModuleType
database: ModuleType

database.sqlite_url = "sqlite://"
database.engine = create_engine(database.sqlite_url)
app.engine = database.engine
calls = []

new_print = get_testing_print_function(calls)

with patch("builtins.print", new=new_print):
app.main()
assert calls == expected_calls
@pytest.fixture(
name="modules",
params=[
"tutorial001",
pytest.param("tutorial001_py39", marks=needs_py39),
pytest.param("tutorial001_py310", marks=needs_py310),
],
)
def get_modules(request: pytest.FixtureRequest) -> Modules:
app_module = importlib.import_module(
f"docs_src.tutorial.code_structure.{request.param}.app"
)
database_module = importlib.import_module(
f"docs_src.tutorial.code_structure.{request.param}.database"
)
database_module.sqlite_url = "sqlite://"
database_module.engine = create_engine(database_module.sqlite_url)
app_module.engine = database_module.engine

return Modules(app=app_module, database=database_module)


def test_tutorial(print_mock: PrintMock, modules: Modules):
modules.app.main()
assert print_mock.calls == expected_calls

This file was deleted.

This file was deleted.


Back | FazBrowse Home | New Git URL