Copy the committed lab 1 sources as-is: src/, student-tests/, bench/, Dockerfile, docker-compose.yml, pyproject.toml, uv.lock, .python-version, config_example.toml, AGENTS.md, CLAUDE.md, .claude/, openspec/, .graphifyignore and KNOWN_ISSUES.md. Lab 1 evidence stays in the lab 1 repository. Merge the new skeleton files with own sections: Makefile (lab 2 targets plus own run, docker, bench and common targets), .gitignore, .dockerignore and .env.example. Rename the image to mtusi-messenger:lab2 and point AGENTS.md at lab 2. The application is still the in-memory lab 1 implementation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
83 lines
2.4 KiB
Python
83 lines
2.4 KiB
Python
"""Настройка набора: адрес стенда, проверка доступности, фикстуры."""
|
|
|
|
import os
|
|
from collections.abc import Iterator
|
|
from typing import Any
|
|
|
|
import httpx
|
|
import pytest
|
|
|
|
from api_client import Actor, Api
|
|
from spec_coverage import COLLECTED, Collected
|
|
|
|
BASE_URL = os.environ.get("BASE_URL", "http://localhost:8080").rstrip("/")
|
|
|
|
|
|
@pytest.hookimpl(tryfirst=True)
|
|
def pytest_collection_modifyitems(
|
|
config: pytest.Config,
|
|
items: list[pytest.Item],
|
|
) -> None:
|
|
"""Маркеры `spec` всех собранных тестов, до отбора по `-k` / `-m`."""
|
|
collected = Collected()
|
|
for item in items:
|
|
collected.modules.add(item.path.name)
|
|
for mark in item.iter_markers("spec"):
|
|
if len(mark.args) != 2 or mark.kwargs:
|
|
raise pytest.UsageError(
|
|
f"{item.nodeid}: spec marker takes (capability, scenario)",
|
|
)
|
|
collected.marks.setdefault(mark.args, []).append(item.nodeid)
|
|
config.stash[COLLECTED] = collected
|
|
|
|
|
|
@pytest.fixture(scope="session", autouse=True)
|
|
def _server_reachable() -> None:
|
|
"""Без сервера прогон останавливается одной строкой, а не 100 ошибками."""
|
|
try:
|
|
resp = httpx.get(f"{BASE_URL}/health/live", timeout=2)
|
|
except httpx.HTTPError as exc:
|
|
pytest.exit(
|
|
f"server is not reachable at {BASE_URL}: {exc!r}",
|
|
returncode=2,
|
|
)
|
|
if resp.status_code != 200:
|
|
pytest.exit(
|
|
f"{BASE_URL}/health/live answered {resp.status_code}: "
|
|
"another service on this port?",
|
|
returncode=2,
|
|
)
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def base_url() -> str:
|
|
return BASE_URL
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def api() -> Iterator[Api]:
|
|
with Api(BASE_URL) as client:
|
|
yield client
|
|
|
|
|
|
@pytest.fixture
|
|
def alice(api: Api) -> Actor:
|
|
return api.register(display_name="Алиса")
|
|
|
|
|
|
@pytest.fixture
|
|
def bob(api: Api) -> Actor:
|
|
return api.register(display_name="Боб")
|
|
|
|
|
|
@pytest.fixture
|
|
def eve(api: Api) -> Actor:
|
|
"""Посторонний: ни в одном чате фикстур не состоит."""
|
|
return api.register(display_name="Ева")
|
|
|
|
|
|
@pytest.fixture
|
|
def chat(api: Api, alice: Actor, bob: Actor) -> dict[str, Any]:
|
|
"""Чат Алисы и Боба."""
|
|
return api.create_chat(alice, bob, title="Алиса и Боб")
|