3ccd94f661
Test Organization: - Create tests/unit/, tests/integration/, tests/system/ directories - Move existing tests into appropriate categories - Add pytest markers (@pytest.mark.unit, @pytest.mark.integration) Shared Fixtures: - Create conftest.py with SQLite engine (for unit tests) - Add PostgreSQL session fixture with transaction rollback - Add TestClient fixture for API tests Configuration: - Update pyproject.toml with asyncio_mode=auto - Add test markers and default addopts - Add aiosqlite dependency for SQLite support E2E Testing: - Initialize Playwright in e2e/ directory - Add playwright.config.ts - Create login flow E2E test Build: - Add test-unit, test-integration, test-system, test-e2e to Makefile - Update test target to run all categories - Add testing documentation to README Note: Some tests have import issues due to missing python-jose package in dev environment. This needs to be addressed separately.
2.5 KiB
2.5 KiB
Context
Current test infrastructure has ~50 backend tests and 12 frontend tests. Backend tests are mixed in a single directory with inconsistent patterns. Some tests require a running PostgreSQL instance even when testing pure logic. There's no E2E test coverage.
Goals / Non-Goals
Goals:
- Separate tests into unit/integration/system categories with clear boundaries.
- Create shared fixtures to eliminate duplication.
- Enable fast unit tests without PostgreSQL (SQLite in-memory).
- Implement proper transaction isolation for integration tests.
- Add E2E tests for critical user journeys (login, project creation).
- Make tests runnable both locally and in Docker.
Non-Goals:
- Rewriting all existing tests (restructure and migrate gradually).
- Adding tests for features that don't exist yet.
- Complex test parallelization setup.
- Performance benchmarking.
Decisions
-
Use SQLite for unit tests, PostgreSQL for integration/system tests
- Rationale: Unit tests should be fast and not require external services.
- SQLite runs in-memory, no Docker needed.
-
Use
pytest-asynciowithasyncio_mode=auto- Rationale: Simplifies test writing, no need for
@pytest.mark.asyncioon every test.
- Rationale: Simplifies test writing, no need for
-
Shared
conftest.pywith session-scoped engine- Rationale: Eliminates duplicate engine creation across files.
- Integration tests use
begin_nested()for transaction rollback.
-
Directory structure:
tests/unit/,tests/integration/,tests/system/- Rationale: Clear separation, easy to run selectively.
pytest -m unitruns all unit tests regardless of location.
-
Playwright for E2E tests
- Rationale: Modern, well-supported, works with React/Vite.
- Tests run against the actual deployed application.
Risks / Trade-offs
- [SQLite vs PostgreSQL behavior differences] -> Document known differences (e.g., JSON operators, asyncpg-specific features).
- [Migration effort for existing tests] -> Migrate gradually, prioritize new tests over rewriting old ones.
- [E2E tests are slower] -> Run them selectively (not on every commit), maybe only in CI or nightly.
Migration Plan
- Create new directory structure.
- Implement shared fixtures in
conftest.py. - Add SQLite support for unit tests.
- Migrate 2-3 existing tests as examples.
- Add Playwright setup and 1-2 E2E tests.
- Update Makefile targets.
- Document testing strategy.
Open Questions
- Should we use
pytest-xdistfor parallel test execution? - Should E2E tests run against the Docker compose setup or a staging environment?