Running Tests for the genai-stack Project
This document provides a comprehensive guide for running tests within the genai-stack project.
Prerequisites
- You have Docker installed and running on your system.
Running Tests
Build the Docker Image:
docker-compose build
This command will build the Docker image for the project, which includes all necessary dependencies and test frameworks.
Run Tests:
docker-compose run --rm genai-stack pytest
This command runs the
pytest
command within the Docker container namedgenai-stack
. The--rm
flag ensures the container is removed after the tests are completed.
Test Structure
The project utilizes the pytest
framework for testing. Test files are located in the tests
directory and follow the naming convention test_<filename>.py
.
Example Test File:
# tests/test_api.py
import requests
def test_api_endpoint():
response = requests.get("http://localhost:8000/api/healthcheck")
assert response.status_code == 200
assert response.json() == {"status": "ok"}
Testing Svelte Components:
Svelte components can be tested using the @testing-library/svelte
library.
Example Test for Svelte Component:
// tests/components/MyComponent.spec.js
import { render, screen, fireEvent } from '@testing-library/svelte';
import MyComponent from './MyComponent.svelte';
describe('MyComponent', () => {
it('should display the correct text', () => {
render(MyComponent, { text: 'Hello World' });
expect(screen.getByText('Hello World')).toBeInTheDocument();
});
it('should handle button click', () => {
render(MyComponent);
const button = screen.getByRole('button');
fireEvent.click(button);
// ... assert changes
});
});
Running Individual Tests
To run specific tests, you can pass the test file or function name to the pytest
command. For example:
docker-compose run --rm genai-stack pytest tests/test_api.py
This command will only run tests from the tests/test_api.py
file.
Coverage Reports
To generate a coverage report, you can use the --cov
flag with pytest
.
docker-compose run --rm genai-stack pytest --cov=./
This command will generate a coverage report for the entire project in the htmlcov
directory.
Additional Information
For more detailed information on pytest
, refer to the official documentation: https://docs.pytest.org/en/latest/