Add pytest infrastructure with API health check tests#65
Add pytest infrastructure with API health check tests#65
Conversation
Co-authored-by: ashcastelinocs124 <149020244+ashcastelinocs124@users.noreply.github.com>
Co-authored-by: ashcastelinocs124 <149020244+ashcastelinocs124@users.noreply.github.com>
Co-authored-by: ashcastelinocs124 <149020244+ashcastelinocs124@users.noreply.github.com>
|
@copilot did it look at my instruction md |
There was a problem hiding this comment.
Pull request overview
This PR establishes foundational pytest infrastructure for the VentureBot project, enabling automated testing of the FastAPI backend. It includes basic health check tests, pytest configuration with test markers, and updated documentation.
- Adds pytest test infrastructure with health endpoint validation
- Configures pytest with markers (unit/integration/slow) and pydantic warning filters
- Updates requirements.txt with httpx dependency for TestClient support
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_api_health.py | Implements health check endpoint tests and FastAPI app structure validation using TestClient fixture |
| tests/init.py | Creates test package marker file |
| pytest.ini | Configures pytest with test discovery patterns, custom markers, and deprecation warning filters |
| requirements.txt | Adds httpx==0.27.2 dependency for FastAPI TestClient support |
| README.md | Adds "Running Tests" section with pytest usage examples |
| from services.api_gateway.app.main import app | ||
|
|
||
|
|
||
| @pytest.fixture |
There was a problem hiding this comment.
Consider adding a scope to the fixture to optimize test performance. Since the TestClient is stateless and doesn't need to be recreated for each test, you could use @pytest.fixture(scope="module") to create it once per test module instead of once per test function.
| @pytest.fixture | |
| @pytest.fixture(scope="module") |
| def test_healthcheck_endpoint(client): | ||
| """Test that the health check endpoint returns OK status.""" | ||
| response = client.get("/healthz") | ||
|
|
||
| assert response.status_code == 200 | ||
| assert response.json() == {"status": "ok"} | ||
|
|
||
|
|
||
| def test_api_structure(): | ||
| """Test that the FastAPI app is properly configured.""" | ||
| # Verify app exists and has expected attributes | ||
| assert app is not None | ||
| assert app.title is not None | ||
|
|
||
| # Verify routers are included | ||
| routes = [route.path for route in app.routes] | ||
| assert "/healthz" in routes | ||
| # Check for routes starting with /api/chat | ||
| assert any(route.startswith("/api/chat") for route in routes) |
There was a problem hiding this comment.
Consider adding test markers to categorize these tests. Since pytest.ini defines markers for unit, integration, and slow tests, you should mark these tests appropriately. For example, @pytest.mark.unit for test_api_structure and @pytest.mark.integration for test_healthcheck_endpoint would help with selective test execution.
| def test_healthcheck_endpoint(client): | ||
| """Test that the health check endpoint returns OK status.""" | ||
| response = client.get("/healthz") | ||
|
|
There was a problem hiding this comment.
The blank line between the response retrieval and assertions is inconsistent with Python style conventions. Consider removing this blank line to keep the related assertions grouped together with the API call they're testing.
Test issue to verify copilot integration. Adds foundational testing infrastructure.
Changes
tests/test_api_health.pywith coverage for/healthzendpoint and FastAPI app structure validationpytest.iniwith test discovery patterns, markers (unit/integration/slow), and pydantic deprecation warning filtershttpx==0.27.2for TestClient supportImplementation
Tests use pytest fixtures for clean app initialization:
Run with:
python -m pytestorpython -m pytest -vfor verbose output.Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
api.scarf.sh/usr/bin/python python -m pytest tests/test_api_health.py -v(dns block)/usr/bin/python python -m pytest tests/(dns block)/usr/bin/python python -m pytest tests/ -v(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.