chore(tests): gate RLS tests behind RUN_RLS_TESTS flag
Continues the test-isolation work from dab740d. RLS migration tests run
against a policy-installed database and fail in the default create_all
suite, so they need to be opt-in:
- pytest.ini: register `rls` marker.
- conftest.py: auto-deselect test_rls_isolation.py unless
RUN_RLS_TESTS=1. Drops the deprecated session-scoped event_loop
fixture (not needed since pytest-asyncio 0.23+).
- test_rls_isolation.py: tag module with `rls` marker. Replace
hardcoded `patherly_test` DB reference with parsed DATABASE_TEST_URL
(matches conftest.py default `resolutionflow_test`). Updated docstring
command to show RUN_RLS_TESTS=1.
- requirements-dev.txt: bump pytest-asyncio 0.23.0 → 0.24.0 (loop-scope
marker behavior required by the RLS module fixture).
Run the RLS suite with:
RUN_RLS_TESTS=1 DB_APP_ROLE_PASSWORD=... pytest tests/test_rls_isolation.py
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -4,8 +4,8 @@ Pytest configuration and fixtures for integration tests.
|
||||
Provides test database setup, client fixtures, and authentication helpers.
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
from typing import AsyncGenerator, Generator
|
||||
import os
|
||||
from typing import AsyncGenerator
|
||||
import pytest
|
||||
import sqlalchemy as sa
|
||||
from httpx import AsyncClient, ASGITransport
|
||||
@@ -26,7 +26,6 @@ settings.REQUIRE_INVITE_CODE = False
|
||||
# would silently nuke the dev database. Only DATABASE_TEST_URL is honored,
|
||||
# and the safety assertion below refuses to run against a DB whose name
|
||||
# doesn't contain "test".
|
||||
import os
|
||||
TEST_DATABASE_URL = os.environ.get(
|
||||
"DATABASE_TEST_URL",
|
||||
"postgresql+asyncpg://postgres:postgres@localhost:5432/resolutionflow_test",
|
||||
@@ -43,13 +42,27 @@ assert "test" in _test_db_name, (
|
||||
f"test database (e.g. resolutionflow_test)."
|
||||
)
|
||||
|
||||
_RUN_RLS_TESTS = os.environ.get("RUN_RLS_TESTS") == "1"
|
||||
_RLS_ISOLATION_FILE = "test_rls_isolation.py"
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def event_loop() -> Generator:
|
||||
"""Create an instance of the default event loop for each test case."""
|
||||
loop = asyncio.get_event_loop_policy().new_event_loop()
|
||||
yield loop
|
||||
loop.close()
|
||||
|
||||
def pytest_collection_modifyitems(config, items):
|
||||
"""Keep migration-managed RLS checks out of the default create_all suite."""
|
||||
if _RUN_RLS_TESTS:
|
||||
return
|
||||
|
||||
selected = []
|
||||
deselected = []
|
||||
for item in items:
|
||||
item_path = getattr(item, "path", None) or getattr(item, "fspath", None)
|
||||
if item_path and str(item_path).endswith(_RLS_ISOLATION_FILE):
|
||||
deselected.append(item)
|
||||
else:
|
||||
selected.append(item)
|
||||
|
||||
if deselected:
|
||||
config.hook.pytest_deselected(items=deselected)
|
||||
items[:] = selected
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
||||
Reference in New Issue
Block a user