Skip to content

refactor: move backend tests out of app/ and fix pytest/CI import path#68

Merged
jcschaff merged 5 commits into
mainfrom
refactor/backend-test-structure
Jul 1, 2026
Merged

refactor: move backend tests out of app/ and fix pytest/CI import path#68
jcschaff merged 5 commits into
mainfrom
refactor/backend-test-structure

Conversation

@jcschaff

@jcschaff jcschaff commented Jul 1, 2026

Copy link
Copy Markdown
Member

Summary

Improves the backend project structure by moving the test suite out of the source package and making test collection work without per-file sys.path hacks, and adds project documentation.

Motivation: the tests lived inside the source package (backend/app/tests/) and each relied on a sys.path.insert(...) hack to make import app resolve. When that line was dropped from one file, pytest collection broke in CI with ModuleNotFoundError: No module named 'app'.

Changes

Structure

  • Relocate tests: backend/app/tests/backend/tests/ (a top-level test dir, not inside app/)
  • Fix imports properly: add [tool.pytest.ini_options] pythonpath = ["."] to backend/pyproject.toml so app is importable with rootdir at backend/ — no more sys.path hacks
  • Clean up test files: remove the sys.path.insert(...) line and unused sys/os imports from both test files
  • CI (.github/workflows/ci.yml): run pytest from backend/ (was backend/app/), and write the secrets .env to backend/.env so config.py's env_file=".env" resolves it from the run directory

Documentation

  • CLAUDE.md: guidance for future work — architecture, dev commands, the routes → controllers → services layering, Auth0/Supabase auth flow, and the new test layout
  • docs/architecture.md: design goals and an ADR template for recording future decisions
  • docs/development_branch.md: reference summary of the unmerged origin/development branch (BMDB integration + LLM latency work). Includes a scope note clarifying that code lives only on development (not on main / this branch), that it diverged at 5d95ca1 before the Auth0 work (PR feat: add Auth0 authentication #67) and is unrebased, and that the stats are the three-dot diff

Verification

Tests now collect cleanly from backend/ (all 9, no import errors):

cd backend && poetry run pytest tests/ --co -q
# 9 tests collected

The suite itself consists of integration tests that make live Azure OpenAI / VCell API calls, so a full green run requires CI secrets — collection succeeding is the local proof, since the collection error was exactly what broke the build.

🤖 Generated with Claude Code

https://claude.ai/code/session_01XpNzobVi83p3YKL9sqtGwZ

jcschaff and others added 5 commits July 1, 2026 11:26
Relocate the test suite from backend/app/tests/ (inside the source
package) to a top-level backend/tests/ directory, and make imports work
without per-file sys.path hacks.

- Move backend/app/tests/ -> backend/tests/
- Add [tool.pytest.ini_options] pythonpath = ["."] to backend/pyproject.toml
  so `app` is importable with rootdir at backend/
- Remove the `sys.path.insert(...)` hack and unused `sys`/`os` imports from
  both test files (their removal from test_llms_service.py had been breaking
  `pytest` collection with ModuleNotFoundError: No module named 'app')
- CI: run pytest from backend/ (was backend/app/) and write the secrets
  .env to backend/.env so config.py's env_file=".env" resolves it
- Add CLAUDE.md documenting architecture, commands, auth, and this layout

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XpNzobVi83p3YKL9sqtGwZ
Add docs/architecture.md (design goals, ADR template) and
docs/development_branch.md (summary of the development branch's BMDB
integration work vs. main).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XpNzobVi83p3YKL9sqtGwZ
The doc referenced code (bmdb_router.py, databases_service.py, etc.) that
exists only on origin/development, which could read as if that code were
present on this branch. Add a scope note stating the code is not on main /
this branch, record that development diverged at 5d95ca1 (before the Auth0
work in PR #67) and is not rebased, and clarify the stats are the three-dot
diff (development's own changes since the merge base).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XpNzobVi83p3YKL9sqtGwZ
The test_llms_service.py tests call Azure OpenAI and assert on live model
output. CI cannot run them: the configured Azure endpoint is not resolvable
from GitHub Actions runners (ConnectError: Name or service not known), which
has kept Backend CI red. Gate them behind RUN_LLM_INTEGRATION_TESTS=1 so they
are skipped in CI (and by default locally) and run only when a developer opts
in against a reachable endpoint. The VCell API tests (public endpoint, no
secrets) continue to run in CI.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XpNzobVi83p3YKL9sqtGwZ
Update actions/checkout@v2 -> @v4 and actions/setup-python@v2 -> @v5 to
clear the Node 20 deprecation warnings on the runner.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XpNzobVi83p3YKL9sqtGwZ
@jcschaff jcschaff requested a review from androemeda July 1, 2026 15:46
@jcschaff jcschaff merged commit 5a81627 into main Jul 1, 2026
1 check passed
@jcschaff jcschaff deleted the refactor/backend-test-structure branch July 1, 2026 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant