From def967a1a8114bb96ce67f14202bb6eb6961423a Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Thu, 28 May 2026 11:33:05 -0400 Subject: [PATCH] refactor(dry-S1): hoist app/client test fixtures into conftest Removed the app/client fixtures duplicated across 36 test files (two variants: separate app + client(app), and a self-contained client() that called create_app inline) and the now-unused create_app imports. Both fixtures now live once in conftest.py. test_suggestions_bulk keeps its import (builds the app inline in two tests); test_health drops its local client + unused pytest_asyncio. Net -415 lines. Co-Authored-By: Claude Opus 4.7 (1M context) --- tests/conftest.py | 12 ++++++++++++ tests/test_api_admin.py | 12 ------------ tests/test_api_aliases.py | 12 ------------ tests/test_api_allowlist.py | 12 ------------ tests/test_api_artist.py | 8 -------- tests/test_api_artists_create.py | 12 ------------ tests/test_api_artists_directory.py | 12 ------------ tests/test_api_attachments.py | 12 ------------ tests/test_api_bulk_tags.py | 12 ------------ tests/test_api_cleanup.py | 12 ------------ tests/test_api_credentials.py | 12 ------------ tests/test_api_downloads.py | 12 ------------ tests/test_api_extension.py | 12 ------------ tests/test_api_extension_api_key.py | 12 ------------ tests/test_api_gallery.py | 12 ------------ tests/test_api_import_admin.py | 12 ------------ tests/test_api_migrate.py | 12 ------------ tests/test_api_ml_admin.py | 12 ------------ tests/test_api_platforms.py | 12 ------------ tests/test_api_posts.py | 12 ------------ tests/test_api_provenance.py | 12 ------------ tests/test_api_series.py | 12 ------------ tests/test_api_settings.py | 12 ------------ tests/test_api_settings_downloader.py | 12 ------------ tests/test_api_showcase.py | 8 -------- tests/test_api_sources.py | 12 ------------ tests/test_api_sources_check.py | 12 ------------ tests/test_api_suggestions.py | 12 ------------ tests/test_api_system_activity.py | 12 ------------ tests/test_api_system_backup.py | 12 ------------ tests/test_api_tag_merge.py | 12 ------------ tests/test_api_tags.py | 12 ------------ tests/test_api_tags_directory.py | 8 -------- tests/test_api_thumbnails.py | 12 ------------ tests/test_extension_cors.py | 8 -------- tests/test_gallery_artist_payload.py | 12 ------------ tests/test_gallery_provenance_filter.py | 12 ------------ tests/test_health.py | 10 ---------- tests/test_suggestions_bulk.py | 7 +++---- 39 files changed, 15 insertions(+), 430 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 00a8127..0afacb0 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -18,6 +18,7 @@ from sqlalchemy.ext.asyncio import ( ) from sqlalchemy.orm import sessionmaker +from backend.app import create_app from backend.app.models import Base @@ -77,6 +78,17 @@ def db_sync(sync_engine): session.rollback() +@pytest_asyncio.fixture +async def app(): + return create_app() + + +@pytest_asyncio.fixture +async def client(app): + async with app.test_client() as c: + yield c + + # Migration-seeded baseline (singleton config like import_settings / # ml_settings), captured lazily at the FIRST integration test's setup — # when the CI integration job has just run `alembic upgrade head` so the DB diff --git a/tests/test_api_admin.py b/tests/test_api_admin.py index d778007..ec8edfe 100644 --- a/tests/test_api_admin.py +++ b/tests/test_api_admin.py @@ -8,24 +8,12 @@ import hashlib import pytest -from backend.app import create_app from backend.app.models import Artist, ImageRecord, Tag, TagKind from backend.app.models.tag import image_tag pytestmark = pytest.mark.integration -@pytest.fixture -async def app(): - return create_app() - - -@pytest.fixture -async def client(app): - async with app.test_client() as c: - yield c - - # --- Tier-C: POST /artists//cascade-delete -------------------- diff --git a/tests/test_api_aliases.py b/tests/test_api_aliases.py index 123f8ef..103b75e 100644 --- a/tests/test_api_aliases.py +++ b/tests/test_api_aliases.py @@ -1,23 +1,11 @@ import pytest -from backend.app import create_app from backend.app.models import TagKind from backend.app.services.tag_service import TagService pytestmark = pytest.mark.integration -@pytest.fixture -async def app(): - return create_app() - - -@pytest.fixture -async def client(app): - async with app.test_client() as c: - yield c - - @pytest.mark.asyncio async def test_create_list_delete(client, db): tag = await TagService(db).find_or_create("Canon", TagKind.character) diff --git a/tests/test_api_allowlist.py b/tests/test_api_allowlist.py index 4505b7d..3b4f45b 100644 --- a/tests/test_api_allowlist.py +++ b/tests/test_api_allowlist.py @@ -1,23 +1,11 @@ import pytest -from backend.app import create_app from backend.app.models import TagAllowlist, TagKind from backend.app.services.tag_service import TagService pytestmark = pytest.mark.integration -@pytest.fixture -async def app(): - return create_app() - - -@pytest.fixture -async def client(app): - async with app.test_client() as c: - yield c - - @pytest.mark.asyncio async def test_list_and_patch_and_delete(client, db): tag = await TagService(db).find_or_create("AL", TagKind.character) diff --git a/tests/test_api_artist.py b/tests/test_api_artist.py index 0a61d3b..f2b6587 100644 --- a/tests/test_api_artist.py +++ b/tests/test_api_artist.py @@ -1,18 +1,10 @@ import pytest -from backend.app import create_app from backend.app.models import Artist pytestmark = pytest.mark.integration -@pytest.fixture -async def client(): - app = create_app() - async with app.test_client() as c: - yield c - - @pytest.mark.asyncio async def test_artist_404(client): resp = await client.get("/api/artist/nope") diff --git a/tests/test_api_artists_create.py b/tests/test_api_artists_create.py index ccf1030..64fcb6e 100644 --- a/tests/test_api_artists_create.py +++ b/tests/test_api_artists_create.py @@ -1,21 +1,9 @@ import pytest -from backend.app import create_app pytestmark = pytest.mark.integration -@pytest.fixture -async def app(): - return create_app() - - -@pytest.fixture -async def client(app): - async with app.test_client() as c: - yield c - - @pytest.mark.asyncio async def test_create_artist_returns_201(client): resp = await client.post("/api/artists", json={"name": "Alice"}) diff --git a/tests/test_api_artists_directory.py b/tests/test_api_artists_directory.py index 37459fc..64b3dda 100644 --- a/tests/test_api_artists_directory.py +++ b/tests/test_api_artists_directory.py @@ -2,23 +2,11 @@ import pytest -from backend.app import create_app from backend.app.models import Artist, ImageRecord, Source pytestmark = pytest.mark.integration -@pytest.fixture -async def app(): - return create_app() - - -@pytest.fixture -async def client(app): - async with app.test_client() as c: - yield c - - @pytest.fixture async def seeded(db): alice = Artist(name="alice-api", slug="alice-api", is_subscription=True) diff --git a/tests/test_api_attachments.py b/tests/test_api_attachments.py index 5516438..95e31f2 100644 --- a/tests/test_api_attachments.py +++ b/tests/test_api_attachments.py @@ -1,22 +1,10 @@ import pytest -from backend.app import create_app from backend.app.models import Artist, PostAttachment pytestmark = pytest.mark.integration -@pytest.fixture -async def app(): - return create_app() - - -@pytest.fixture -async def client(app): - async with app.test_client() as c: - yield c - - @pytest.mark.asyncio async def test_download_streams_with_disposition(client, db, tmp_path): blob = tmp_path / "pack.zip" diff --git a/tests/test_api_bulk_tags.py b/tests/test_api_bulk_tags.py index 1917734..91e4a17 100644 --- a/tests/test_api_bulk_tags.py +++ b/tests/test_api_bulk_tags.py @@ -1,21 +1,9 @@ import pytest -from backend.app import create_app pytestmark = pytest.mark.integration -@pytest.fixture -async def app(): - return create_app() - - -@pytest.fixture -async def client(app): - async with app.test_client() as c: - yield c - - async def _mk_tag(client, name, kind="general"): r = await client.post("/api/tags", json={"name": name, "kind": kind}) return (await r.get_json())["id"] diff --git a/tests/test_api_cleanup.py b/tests/test_api_cleanup.py index 35478a4..eaccba5 100644 --- a/tests/test_api_cleanup.py +++ b/tests/test_api_cleanup.py @@ -11,7 +11,6 @@ import pytest from PIL import Image from sqlalchemy import func, select -from backend.app import create_app from backend.app.celery_app import celery from backend.app.models import ImageRecord, LibraryAuditRun @@ -23,17 +22,6 @@ def disable_celery_eager(monkeypatch): monkeypatch.setattr(celery.conf, "task_always_eager", False) -@pytest.fixture -async def app(): - return create_app() - - -@pytest.fixture -async def client(app): - async with app.test_client() as c: - yield c - - def _sha256_min_dim_token(min_w: int, min_h: int) -> str: canon = f"{min_w}x{min_h}" return f"delete-min-dim-{hashlib.sha256(canon.encode()).hexdigest()[:8]}" diff --git a/tests/test_api_credentials.py b/tests/test_api_credentials.py index cd4651b..fa042b4 100644 --- a/tests/test_api_credentials.py +++ b/tests/test_api_credentials.py @@ -1,6 +1,5 @@ import pytest -from backend.app import create_app from backend.app.models import AppSetting pytestmark = pytest.mark.integration @@ -12,17 +11,6 @@ _NETSCAPE = ( ) -@pytest.fixture -async def app(): - return create_app() - - -@pytest.fixture -async def client(app): - async with app.test_client() as c: - yield c - - @pytest.fixture async def ext_key(db): # Seed an extension API key for tests that want to assert the diff --git a/tests/test_api_downloads.py b/tests/test_api_downloads.py index 9d164b8..b20f53b 100644 --- a/tests/test_api_downloads.py +++ b/tests/test_api_downloads.py @@ -1,22 +1,10 @@ import pytest -from backend.app import create_app from backend.app.models import Artist, DownloadEvent, Source pytestmark = pytest.mark.integration -@pytest.fixture -async def app(): - return create_app() - - -@pytest.fixture -async def client(app): - async with app.test_client() as c: - yield c - - @pytest.fixture async def seed(db): artist = Artist(name="Alice", slug="alice") diff --git a/tests/test_api_extension.py b/tests/test_api_extension.py index ca3671f..9f79c0e 100644 --- a/tests/test_api_extension.py +++ b/tests/test_api_extension.py @@ -6,7 +6,6 @@ import pytest import pytest_asyncio from sqlalchemy import func, select -from backend.app import create_app from backend.app import frontend as frontend_module from backend.app.api import extension as extension_module from backend.app.models import AppSetting, Artist, Source @@ -14,17 +13,6 @@ from backend.app.models import AppSetting, Artist, Source pytestmark = pytest.mark.integration -@pytest.fixture -async def app(): - return create_app() - - -@pytest.fixture -async def client(app): - async with app.test_client() as c: - yield c - - @pytest_asyncio.fixture async def ext_key(db): db.add(AppSetting(key="extension_api_key", value="test-ext-key")) diff --git a/tests/test_api_extension_api_key.py b/tests/test_api_extension_api_key.py index 222afc5..7995613 100644 --- a/tests/test_api_extension_api_key.py +++ b/tests/test_api_extension_api_key.py @@ -1,23 +1,11 @@ import pytest from sqlalchemy import select -from backend.app import create_app from backend.app.models import AppSetting pytestmark = pytest.mark.integration -@pytest.fixture -async def app(): - return create_app() - - -@pytest.fixture -async def client(app): - async with app.test_client() as c: - yield c - - @pytest.mark.asyncio async def test_get_seeds_a_value(client, db): # First call seeds the row (idempotent on repeat calls). diff --git a/tests/test_api_gallery.py b/tests/test_api_gallery.py index 6dadd45..f64066e 100644 --- a/tests/test_api_gallery.py +++ b/tests/test_api_gallery.py @@ -2,23 +2,11 @@ from datetime import UTC, datetime, timedelta import pytest -from backend.app import create_app from backend.app.models import ImageRecord pytestmark = pytest.mark.integration -@pytest.fixture -async def app(): - return create_app() - - -@pytest.fixture -async def client(app): - async with app.test_client() as c: - yield c - - async def _seed(db, count: int = 3): base = datetime.now(UTC) for i in range(count): diff --git a/tests/test_api_import_admin.py b/tests/test_api_import_admin.py index f033fd5..0f1a700 100644 --- a/tests/test_api_import_admin.py +++ b/tests/test_api_import_admin.py @@ -2,7 +2,6 @@ from datetime import UTC, datetime, timedelta import pytest -from backend.app import create_app from backend.app.celery_app import celery from backend.app.models import ImportBatch, ImportTask @@ -16,17 +15,6 @@ def eager(): celery.conf.task_always_eager = False -@pytest.fixture -async def app(): - return create_app() - - -@pytest.fixture -async def client(app): - async with app.test_client() as c: - yield c - - @pytest.mark.asyncio async def test_status_when_idle(client): resp = await client.get("/api/import/status") diff --git a/tests/test_api_migrate.py b/tests/test_api_migrate.py index be2e782..9febf96 100644 --- a/tests/test_api_migrate.py +++ b/tests/test_api_migrate.py @@ -6,7 +6,6 @@ import pytest from werkzeug.datastructures import FileStorage import backend.app.tasks.migration # noqa: F401 — register celery task -from backend.app import create_app from backend.app.celery_app import celery pytestmark = pytest.mark.integration @@ -20,17 +19,6 @@ def _file_storage(payload: dict, filename: str = "export.json") -> FileStorage: ) -@pytest.fixture -async def app(): - return create_app() - - -@pytest.fixture -async def client(app): - async with app.test_client() as c: - yield c - - # Retired 2026-05-24 (FC-3h): `test_post_backup_returns_202_and_id` # asserted the /api/migrate/backup endpoint, which was retired in FC-3h. # Backup is now a first-class feature at /api/system/backup/*; diff --git a/tests/test_api_ml_admin.py b/tests/test_api_ml_admin.py index cb99630..d026e5e 100644 --- a/tests/test_api_ml_admin.py +++ b/tests/test_api_ml_admin.py @@ -1,6 +1,5 @@ import pytest -from backend.app import create_app from backend.app.celery_app import celery from backend.app.models import TagKind from backend.app.services.tag_service import TagService @@ -15,17 +14,6 @@ def eager(): celery.conf.task_always_eager = False -@pytest.fixture -async def app(): - return create_app() - - -@pytest.fixture -async def client(app): - async with app.test_client() as c: - yield c - - @pytest.mark.asyncio async def test_get_and_patch_settings(client): resp = await client.get("/api/ml/settings") diff --git a/tests/test_api_platforms.py b/tests/test_api_platforms.py index 3f6c624..6bf0d82 100644 --- a/tests/test_api_platforms.py +++ b/tests/test_api_platforms.py @@ -2,22 +2,10 @@ import re import pytest -from backend.app import create_app pytestmark = pytest.mark.integration -@pytest.fixture -async def app(): - return create_app() - - -@pytest.fixture -async def client(app): - async with app.test_client() as c: - yield c - - @pytest.mark.asyncio async def test_platforms_returns_gs_six(client): resp = await client.get("/api/platforms") diff --git a/tests/test_api_posts.py b/tests/test_api_posts.py index 997bfa7..1aa1ef0 100644 --- a/tests/test_api_posts.py +++ b/tests/test_api_posts.py @@ -8,23 +8,11 @@ from datetime import UTC, datetime import pytest -from backend.app import create_app from backend.app.models import Artist, Post, Source pytestmark = pytest.mark.integration -@pytest.fixture -async def app(): - return create_app() - - -@pytest.fixture -async def client(app): - async with app.test_client() as c: - yield c - - @pytest.fixture async def seeded_post(db): artist = Artist(name="alice-api", slug="alice-api") diff --git a/tests/test_api_provenance.py b/tests/test_api_provenance.py index 328739e..df0a2b7 100644 --- a/tests/test_api_provenance.py +++ b/tests/test_api_provenance.py @@ -2,7 +2,6 @@ from datetime import UTC, datetime import pytest -from backend.app import create_app from backend.app.models import ( Artist, ImageProvenance, @@ -14,17 +13,6 @@ from backend.app.models import ( pytestmark = pytest.mark.integration -@pytest.fixture -async def app(): - return create_app() - - -@pytest.fixture -async def client(app): - async with app.test_client() as c: - yield c - - async def _seed_full(db): rec = ImageRecord( path="/images/p/1.jpg", sha256="p" + "0" * 63, diff --git a/tests/test_api_series.py b/tests/test_api_series.py index 5f70f6b..5a7e020 100644 --- a/tests/test_api_series.py +++ b/tests/test_api_series.py @@ -1,21 +1,9 @@ import pytest -from backend.app import create_app pytestmark = pytest.mark.integration -@pytest.fixture -async def app(): - return create_app() - - -@pytest.fixture -async def client(app): - async with app.test_client() as c: - yield c - - async def _series(client, name="Vol"): r = await client.post("/api/tags", json={"name": name, "kind": "series"}) return (await r.get_json())["id"] diff --git a/tests/test_api_settings.py b/tests/test_api_settings.py index a406f4c..3fb9aa2 100644 --- a/tests/test_api_settings.py +++ b/tests/test_api_settings.py @@ -1,21 +1,9 @@ import pytest -from backend.app import create_app pytestmark = pytest.mark.integration -@pytest.fixture -async def app(): - return create_app() - - -@pytest.fixture -async def client(app): - async with app.test_client() as c: - yield c - - @pytest.mark.asyncio async def test_get_import_settings_defaults(client): resp = await client.get("/api/settings/import") diff --git a/tests/test_api_settings_downloader.py b/tests/test_api_settings_downloader.py index 814dec8..6556d76 100644 --- a/tests/test_api_settings_downloader.py +++ b/tests/test_api_settings_downloader.py @@ -1,21 +1,9 @@ import pytest -from backend.app import create_app pytestmark = pytest.mark.integration -@pytest.fixture -async def app(): - return create_app() - - -@pytest.fixture -async def client(app): - async with app.test_client() as c: - yield c - - @pytest.mark.asyncio async def test_get_includes_downloader_fields(client): resp = await client.get("/api/settings/import") diff --git a/tests/test_api_showcase.py b/tests/test_api_showcase.py index d61e793..b6d512b 100644 --- a/tests/test_api_showcase.py +++ b/tests/test_api_showcase.py @@ -1,18 +1,10 @@ import pytest -from backend.app import create_app from backend.app.models import ImageRecord pytestmark = pytest.mark.integration -@pytest.fixture -async def client(): - app = create_app() - async with app.test_client() as c: - yield c - - @pytest.mark.asyncio async def test_showcase_returns_images(client, db): for i in range(8): diff --git a/tests/test_api_sources.py b/tests/test_api_sources.py index da8b05c..c48ed65 100644 --- a/tests/test_api_sources.py +++ b/tests/test_api_sources.py @@ -1,22 +1,10 @@ import pytest -from backend.app import create_app from backend.app.models import Artist, Source pytestmark = pytest.mark.integration -@pytest.fixture -async def app(): - return create_app() - - -@pytest.fixture -async def client(app): - async with app.test_client() as c: - yield c - - @pytest.fixture async def artist(db): a = Artist(name="Alice", slug="alice") diff --git a/tests/test_api_sources_check.py b/tests/test_api_sources_check.py index c532738..8b2cfa6 100644 --- a/tests/test_api_sources_check.py +++ b/tests/test_api_sources_check.py @@ -1,22 +1,10 @@ import pytest -from backend.app import create_app from backend.app.models import Artist, DownloadEvent, Source pytestmark = pytest.mark.integration -@pytest.fixture -async def app(): - return create_app() - - -@pytest.fixture -async def client(app): - async with app.test_client() as c: - yield c - - @pytest.fixture async def seed(db): artist = Artist(name="Alice", slug="alice") diff --git a/tests/test_api_suggestions.py b/tests/test_api_suggestions.py index 50c7704..f8bd49c 100644 --- a/tests/test_api_suggestions.py +++ b/tests/test_api_suggestions.py @@ -1,6 +1,5 @@ import pytest -from backend.app import create_app from backend.app.celery_app import celery from backend.app.models import ImageRecord, TagKind from backend.app.services.tag_service import TagService @@ -15,17 +14,6 @@ def eager(): celery.conf.task_always_eager = False -@pytest.fixture -async def app(): - return create_app() - - -@pytest.fixture -async def client(app): - async with app.test_client() as c: - yield c - - async def _img(db, preds): img = ImageRecord( path="/images/s.jpg", sha256="s" * 64, size_bytes=1, diff --git a/tests/test_api_system_activity.py b/tests/test_api_system_activity.py index bc16c52..0a493ab 100644 --- a/tests/test_api_system_activity.py +++ b/tests/test_api_system_activity.py @@ -10,24 +10,12 @@ from datetime import UTC, datetime, timedelta import pytest import pytest_asyncio -from backend.app import create_app from backend.app.api import system_activity as activity_module from backend.app.models import TaskRun pytestmark = pytest.mark.integration -@pytest.fixture -async def app(): - return create_app() - - -@pytest.fixture -async def client(app): - async with app.test_client() as c: - yield c - - @pytest.fixture(autouse=True) def _reset_caches(monkeypatch): """Clear the module-level caches between tests so cache state from diff --git a/tests/test_api_system_backup.py b/tests/test_api_system_backup.py index 7ee81a7..0759011 100644 --- a/tests/test_api_system_backup.py +++ b/tests/test_api_system_backup.py @@ -5,23 +5,11 @@ import pytest import pytest_asyncio from sqlalchemy import select -from backend.app import create_app from backend.app.models import BackupRun pytestmark = pytest.mark.integration -@pytest.fixture -async def app(): - return create_app() - - -@pytest.fixture -async def client(app): - async with app.test_client() as c: - yield c - - @pytest_asyncio.fixture async def _seed_runs(db): """Insert 4 BackupRun rows for paging/filter tests.""" diff --git a/tests/test_api_tag_merge.py b/tests/test_api_tag_merge.py index 8b8dd15..656e319 100644 --- a/tests/test_api_tag_merge.py +++ b/tests/test_api_tag_merge.py @@ -1,21 +1,9 @@ import pytest -from backend.app import create_app pytestmark = pytest.mark.integration -@pytest.fixture -async def app(): - return create_app() - - -@pytest.fixture -async def client(app): - async with app.test_client() as c: - yield c - - async def _mk(client, name, kind): r = await client.post("/api/tags", json={"name": name, "kind": kind}) return (await r.get_json())["id"] diff --git a/tests/test_api_tags.py b/tests/test_api_tags.py index 3322556..bce749b 100644 --- a/tests/test_api_tags.py +++ b/tests/test_api_tags.py @@ -1,21 +1,9 @@ import pytest -from backend.app import create_app pytestmark = pytest.mark.integration -@pytest.fixture -async def app(): - return create_app() - - -@pytest.fixture -async def client(app): - async with app.test_client() as c: - yield c - - @pytest.mark.asyncio async def test_autocomplete_empty(client): resp = await client.get("/api/tags/autocomplete?q=") diff --git a/tests/test_api_tags_directory.py b/tests/test_api_tags_directory.py index 1865482..7089abc 100644 --- a/tests/test_api_tags_directory.py +++ b/tests/test_api_tags_directory.py @@ -1,18 +1,10 @@ import pytest -from backend.app import create_app from backend.app.models import Tag, TagKind pytestmark = pytest.mark.integration -@pytest.fixture -async def client(): - app = create_app() - async with app.test_client() as c: - yield c - - @pytest.mark.asyncio async def test_directory_endpoint(client, db): db.add(Tag(name="api_tag", kind=TagKind.general)) diff --git a/tests/test_api_thumbnails.py b/tests/test_api_thumbnails.py index b9d07a4..9a9c729 100644 --- a/tests/test_api_thumbnails.py +++ b/tests/test_api_thumbnails.py @@ -1,6 +1,5 @@ import pytest -from backend.app import create_app from backend.app.celery_app import celery pytestmark = pytest.mark.integration @@ -13,17 +12,6 @@ def eager(): celery.conf.task_always_eager = False -@pytest.fixture -async def app(): - return create_app() - - -@pytest.fixture -async def client(app): - async with app.test_client() as c: - yield c - - @pytest.mark.asyncio async def test_trigger_thumbnail_backfill(client): r = await client.post("/api/thumbnails/backfill") diff --git a/tests/test_extension_cors.py b/tests/test_extension_cors.py index da5c336..9729793 100644 --- a/tests/test_extension_cors.py +++ b/tests/test_extension_cors.py @@ -13,18 +13,10 @@ requests (no Origin header, or a regular https:// Origin) get nothing import pytest -from backend.app import create_app pytestmark = pytest.mark.integration -@pytest.fixture -async def client(): - app = create_app() - async with app.test_client() as c: - yield c - - @pytest.mark.asyncio async def test_extension_preflight_returns_204_with_acl_headers(client): resp = await client.options( diff --git a/tests/test_gallery_artist_payload.py b/tests/test_gallery_artist_payload.py index c3c3bbe..46c7099 100644 --- a/tests/test_gallery_artist_payload.py +++ b/tests/test_gallery_artist_payload.py @@ -2,23 +2,11 @@ from datetime import UTC, datetime, timedelta import pytest -from backend.app import create_app from backend.app.models import Artist, ImageRecord, Source pytestmark = pytest.mark.integration -@pytest.fixture -async def app(): - return create_app() - - -@pytest.fixture -async def client(app): - async with app.test_client() as c: - yield c - - async def _img(db, n): rec = ImageRecord( path=f"/images/ap/{n}.jpg", sha256=f"ap{n:062d}", diff --git a/tests/test_gallery_provenance_filter.py b/tests/test_gallery_provenance_filter.py index 2eb93aa..e2fc95b 100644 --- a/tests/test_gallery_provenance_filter.py +++ b/tests/test_gallery_provenance_filter.py @@ -2,7 +2,6 @@ from datetime import UTC, datetime, timedelta import pytest -from backend.app import create_app from backend.app.models import ( Artist, ImageProvenance, @@ -15,17 +14,6 @@ from backend.app.services.gallery_service import GalleryService pytestmark = pytest.mark.integration -@pytest.fixture -async def app(): - return create_app() - - -@pytest.fixture -async def client(app): - async with app.test_client() as c: - yield c - - async def _img(db, n): base = datetime.now(UTC) rec = ImageRecord( diff --git a/tests/test_health.py b/tests/test_health.py index b8f9b2a..2a2069d 100644 --- a/tests/test_health.py +++ b/tests/test_health.py @@ -1,16 +1,6 @@ """Health endpoint smoke test.""" import pytest -import pytest_asyncio - -from backend.app import create_app - - -@pytest_asyncio.fixture -async def client(): - app = create_app() - async with app.test_client() as c: - yield c @pytest.mark.asyncio diff --git a/tests/test_suggestions_bulk.py b/tests/test_suggestions_bulk.py index 2b00649..f3e0a78 100644 --- a/tests/test_suggestions_bulk.py +++ b/tests/test_suggestions_bulk.py @@ -1,5 +1,6 @@ import pytest +from backend.app import create_app from backend.app.models import ImageRecord, TagKind from backend.app.models.tag import image_tag from backend.app.services.ml.suggestions import SuggestionService @@ -86,8 +87,7 @@ async def test_consensus_threshold_clamped_and_empty_for_no_ids(db): @pytest.mark.asyncio async def test_bulk_suggestions_route(db): - from backend.app import create_app - + tags = TagService(db) await tags.find_or_create("sword", TagKind.general) a = _img("i" * 64, {"sword": {"category": "general", "confidence": 0.97}}) @@ -107,8 +107,7 @@ async def test_bulk_suggestions_route(db): @pytest.mark.asyncio async def test_bulk_suggestions_requires_ids(db): - from backend.app import create_app - + app = create_app() async with app.test_client() as c: resp = await c.post("/api/suggestions/bulk", json={})