lint pipe fixes
All checks were successful
ci/woodpecker/push/tests Pipeline was successful
ci/woodpecker/push/lints Pipeline was successful

This commit is contained in:
2026-04-19 23:16:09 +03:00
parent fd5e6a5dcb
commit af17b5b3bf
9 changed files with 53 additions and 1 deletions

BIN
.coverage Normal file

Binary file not shown.

View File

@@ -8,5 +8,5 @@ steps:
commands:
- pip install uv
- uv sync --no-dev --group tests
- uv run pytest
- uv run pytest --cov=app --cov-fail-under=70 --cov-report=term-missing

0
app/__init__.py Normal file
View File

Binary file not shown.

Binary file not shown.

View File

@@ -17,8 +17,10 @@ dev = [
"pre-commit>=4.5.1",
]
tests = [
"httpx>=0.28.1",
"pytest>=9.0.3",
"pytest-asyncio>=1.3.0",
"pytest-cov>=7.1.0",
]
lints = [
"black>=23.7.0",
@@ -28,3 +30,12 @@ lints = [
types = [
"mypy>=1.20.1",
]
[tool.pytest.ini_options]
asyncio_mode = "auto"
asyncio_default_fixture_loop_scope = "function"
addopts = "--cov=src --cov-report=term"
pythonpath = "."
testpaths = "tests"
xfail_strict = true

41
tests/test_app_run.py Normal file
View File

@@ -0,0 +1,41 @@
from contextlib import asynccontextmanager
from unittest.mock import patch
import pytest
from fastapi import FastAPI
# Предполагаем, что тестируемый модуль называется `myapp`
# Импортируем из него нужные объекты
from app.main import app_factory, lifespan, main
@pytest.mark.asyncio
async def test_lifespan():
"""Проверяет, что lifespan является корректным асинхронным контекстным менеджером."""
app = FastAPI()
# Проверяем, что lifespan - это asynccontextmanager
assert isinstance(lifespan, asynccontextmanager(lifespan).__class__)
# Проверяем, что контекстный менеджер работает (ничего не ломается)
async with lifespan(app):
pass # Просто убеждаемся, что yield отрабатывает
def test_app_factory():
"""Проверяет, что app_factory создаёт правильное приложение FastAPI с переданным lifespan."""
app = app_factory()
assert isinstance(app, FastAPI)
# Проверяем, что lifespan приложения установлен на функцию lifespan
assert app.router.lifespan_context == lifespan
@patch("app.main.uvicorn.run")
def test_main(mock_uvicorn_run):
"""Проверяет, что main вызывает uvicorn.run с правильными параметрами."""
main()
mock_uvicorn_run.assert_called_once_with(
app_factory,
factory=True,
host="0.0.0.0",
port=8000, # Предполагаемый порт (в коде обрезано, но обычно 8000)
)