-
Notifications
You must be signed in to change notification settings - Fork 31
146 lines (131 loc) · 4.69 KB
/
python-tests.yml
File metadata and controls
146 lines (131 loc) · 4.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
name: Python Tests
on:
push:
branches: [ master, main, develop ]
paths:
- 'whyis/**/*.py'
- 'tests/**/*.py'
- 'setup.py'
- 'pytest.ini'
- '.github/workflows/python-tests.yml'
pull_request:
branches: [ master, main, develop ]
paths:
- 'whyis/**/*.py'
- 'tests/**/*.py'
- 'setup.py'
- 'pytest.ini'
- '.github/workflows/python-tests.yml'
jobs:
test:
name: Run Python Tests
runs-on: ubuntu-latest
timeout-minutes: 45
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11']
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y \
build-essential \
libxml2-dev \
libxslt1-dev \
zlib1g-dev \
redis-server
- name: Install Python dependencies
timeout-minutes: 15
run: |
python -m pip install --upgrade pip setuptools wheel
# Install test dependencies first (lightweight)
pip install -r requirements-test.txt
# Install core dependencies needed for unit tests (without full whyis package)
# Use --no-deps where possible to avoid dependency resolution loops
pip install rdflib rdflib-jsonld Flask Flask-Security-Too Flask-Script Flask-PluginEngine
pip install filedepot Markdown
# Optional dependencies - skip if they cause issues
pip install celery eventlet redislite nltk || true
pip install sadi setlr sdd2rdf oxrdflib || true
- name: Start Redis
run: |
sudo systemctl start redis-server
redis-cli ping
- name: Run unit tests with pytest
timeout-minutes: 20
env:
CI: true
PYTHONUNBUFFERED: 1
run: |
mkdir -p test-results/py
# Run tests with verbose output and no timeout
pytest tests/unit/ \
--verbose \
--tb=short \
--junit-xml=test-results/py/junit-unit.xml \
--cov=whyis \
--cov-report=xml:test-results/py/coverage-unit.xml \
--cov-report=html:test-results/py/htmlcov-unit \
--cov-report=term \
-p no:timeout
- name: Run API tests with pytest
timeout-minutes: 10
env:
CI: true
run: |
pytest tests/api/ \
--verbose \
--tb=short \
--junit-xml=test-results/py/junit-api.xml \
--cov=whyis \
--cov-append \
--cov-report=xml:test-results/py/coverage-api.xml \
--cov-report=html:test-results/py/htmlcov-api \
--cov-report=term \
|| echo "API tests failed or not found, continuing..."
- name: Generate combined coverage report
if: matrix.python-version == '3.11'
run: |
coverage combine || true
coverage report || true
coverage xml -o test-results/py/coverage-combined.xml || true
coverage html -d test-results/py/htmlcov-combined || true
- name: Upload coverage to Codecov
if: matrix.python-version == '3.11'
uses: codecov/codecov-action@v4
with:
files: test-results/py/coverage-combined.xml,test-results/py/coverage-unit.xml,test-results/py/coverage-api.xml
flags: python-tests
name: python-coverage-${{ matrix.python-version }}
fail_ci_if_error: false
- name: Archive test results
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results-python-${{ matrix.python-version }}
path: |
test-results/py/
retention-days: 30
- name: Comment test results on PR
if: github.event_name == 'pull_request' && matrix.python-version == '3.11'
uses: actions/github-script@v7
continue-on-error: true
with:
script: |
const fs = require('fs');
const testResultsDir = './test-results/py';
if (fs.existsSync(testResultsDir)) {
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '✅ Python tests completed! Coverage reports available in artifacts.'
});
}