Skip to content

Commit 3fdd7c5

Browse files
committed
ci: Add comprehensive GitHub Actions workflow for tests and coverage
- Create .github/workflows/tests.yml with: - Multi-version Python testing (3.11, 3.12) - Test coverage reporting with pytest-cov - Codecov integration for coverage badges - Test result publishing and artifact uploads - PR comments with coverage reports - Add pytest-cov and pytest-xdist to requirements.txt - Create pytest.ini for pytest configuration: - Test discovery and markers - Coverage options - Asyncio configuration - Logging and warning filters This enables: - Automated testing on push and PR - Coverage tracking and badges - Test result visibility in PRs - Multi-version Python compatibility testing
1 parent 10f804c commit 3fdd7c5

3 files changed

Lines changed: 190 additions & 0 deletions

File tree

.github/workflows/tests.yml

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
pull_request:
7+
branches: [ main, develop ]
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: read
12+
pull-requests: write
13+
14+
concurrency:
15+
group: ${{ github.workflow }}-${{ github.ref }}
16+
cancel-in-progress: true
17+
18+
jobs:
19+
test:
20+
name: Test on Python ${{ matrix.python-version }}
21+
runs-on: ubuntu-latest
22+
timeout-minutes: 30
23+
24+
strategy:
25+
matrix:
26+
python-version: ["3.11", "3.12"]
27+
fail-fast: false
28+
29+
steps:
30+
- name: Checkout code
31+
uses: actions/checkout@v4
32+
33+
- name: Set up Python ${{ matrix.python-version }}
34+
uses: actions/setup-python@v5
35+
with:
36+
python-version: ${{ matrix.python-version }}
37+
cache: 'pip'
38+
39+
- name: Install dependencies
40+
run: |
41+
python -m pip install --upgrade pip
42+
pip install -r requirements.txt
43+
pip install pytest pytest-asyncio pytest-cov pytest-xdist
44+
45+
- name: Run tests with coverage
46+
run: |
47+
pytest tests/ \
48+
--cov=backend \
49+
--cov=backend.api \
50+
--cov=backend.services \
51+
--cov=backend.learning \
52+
--cov=backend.vector_db \
53+
--cov=backend.validators \
54+
--cov-report=xml \
55+
--cov-report=html \
56+
--cov-report=term \
57+
--junit-xml=junit.xml \
58+
-v \
59+
--tb=short \
60+
--maxfail=5
61+
env:
62+
ENVIRONMENT: test
63+
DEEPSEEK_API_KEY: ${{ secrets.DEEPSEEK_API_KEY || 'test_key' }}
64+
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY || 'test_key' }}
65+
66+
- name: Upload coverage to Codecov
67+
uses: codecov/codecov-action@v4
68+
with:
69+
file: ./coverage.xml
70+
flags: unittests
71+
name: codecov-umbrella
72+
fail_ci_if_error: false
73+
token: ${{ secrets.CODECOV_TOKEN }}
74+
75+
- name: Upload test results
76+
uses: actions/upload-artifact@v4
77+
if: always()
78+
with:
79+
name: test-results-${{ matrix.python-version }}
80+
path: |
81+
junit.xml
82+
htmlcov/
83+
retention-days: 7
84+
85+
- name: Publish test results
86+
uses: EnricoMi/publish-unit-test-result-action@v2
87+
if: always()
88+
with:
89+
files: junit.xml
90+
check_name: "Test Results (Python ${{ matrix.python-version }})"
91+
comment_mode: create new
92+
report_individual_runs: true
93+
94+
coverage:
95+
name: Coverage Report
96+
runs-on: ubuntu-latest
97+
needs: test
98+
if: github.event_name == 'pull_request'
99+
100+
steps:
101+
- name: Checkout code
102+
uses: actions/checkout@v4
103+
104+
- name: Set up Python
105+
uses: actions/setup-python@v5
106+
with:
107+
python-version: "3.12"
108+
cache: 'pip'
109+
110+
- name: Install dependencies
111+
run: |
112+
python -m pip install --upgrade pip
113+
pip install -r requirements.txt
114+
pip install pytest pytest-asyncio pytest-cov
115+
116+
- name: Generate coverage report
117+
run: |
118+
pytest tests/ \
119+
--cov=backend \
120+
--cov=backend.api \
121+
--cov=backend.services \
122+
--cov=backend.learning \
123+
--cov=backend.vector_db \
124+
--cov=backend.validators \
125+
--cov-report=term \
126+
--cov-report=html \
127+
-v
128+
env:
129+
ENVIRONMENT: test
130+
131+
- name: Comment PR with coverage
132+
uses: py-cov-action/python-coverage-comment-action@v3
133+
if: github.event_name == 'pull_request'
134+
with:
135+
GITHUB_TOKEN: ${{ github.token }}
136+
MINIMUM_GREEN: 40
137+
MINIMUM_ORANGE: 30
138+

pytest.ini

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
[pytest]
2+
# Pytest configuration for StillMe
3+
4+
# Test discovery
5+
testpaths = tests
6+
python_files = test_*.py
7+
python_classes = Test*
8+
python_functions = test_*
9+
10+
# Markers
11+
markers =
12+
unit: Unit tests (fast, isolated)
13+
integration: Integration tests (slower, may require external services)
14+
slow: Slow tests (may take > 1 second)
15+
api: Tests that make API calls
16+
network: Tests that require network access
17+
database: Tests that use databases
18+
19+
# Output options
20+
addopts =
21+
-v
22+
--strict-markers
23+
--tb=short
24+
--disable-warnings
25+
-ra
26+
27+
# Coverage options (when using pytest-cov)
28+
# Coverage is configured via command line: --cov=backend --cov-report=html
29+
30+
# Asyncio configuration
31+
asyncio_mode = auto
32+
33+
# Minimum Python version
34+
minversion = 7.0
35+
36+
# Test timeout (in seconds) - optional, can be set per test
37+
timeout = 300
38+
39+
# Logging
40+
log_cli = false
41+
log_cli_level = INFO
42+
log_cli_format = %(asctime)s [%(levelname)8s] %(message)s
43+
log_cli_date_format = %Y-%m-%d %H:%M:%S
44+
45+
# Filter warnings
46+
filterwarnings =
47+
ignore::DeprecationWarning
48+
ignore::PendingDeprecationWarning
49+
ignore::UserWarning:chromadb.*
50+

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,5 @@ slowapi==0.1.9
5050
# Development & Testing
5151
pytest==7.4.3
5252
pytest-asyncio==0.21.1
53+
pytest-cov==4.1.0
54+
pytest-xdist==3.5.0

0 commit comments

Comments
 (0)