Skip to content

Commit b9d237e

Browse files
refactor(KDP): improving tests execution
1 parent 84e0b1f commit b9d237e

File tree

11 files changed

+1739
-34
lines changed

11 files changed

+1739
-34
lines changed

.github/workflows/UTESTS.yml

Lines changed: 169 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ on:
77
- main
88
paths:
99
- "**.py"
10+
- "pyproject.toml"
11+
- "test/**"
1012
pull_request:
1113
branches:
1214
- dev
@@ -17,26 +19,184 @@ on:
1719
- synchronize
1820
paths:
1921
- "**.py"
22+
- "pyproject.toml"
23+
- "test/**"
2024
workflow_dispatch:
2125
inputs:
2226
PYTHON_VERSION:
2327
required: false
24-
default: 3.11
28+
default: "3.11"
29+
TEST_TYPE:
30+
description: 'Type of tests to run'
31+
required: false
32+
default: 'all'
33+
type: choice
34+
options:
35+
- all
36+
- fast
37+
- unit
38+
- integration
39+
- smoke
2540

2641
concurrency:
2742
group: "${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}"
2843
cancel-in-progress: true
2944

3045
jobs:
31-
run-unit-test:
32-
runs-on: ["ubuntu-latest"]
46+
# Fast smoke test job for quick feedback
47+
smoke-test:
48+
runs-on: ubuntu-latest
49+
if: github.event_name == 'pull_request'
50+
steps:
51+
- uses: actions/checkout@v4
52+
- name: Set up Python
53+
uses: actions/setup-python@v4
54+
with:
55+
python-version: "3.11"
56+
- name: Install dependencies
57+
run: |
58+
python -m pip install --upgrade pip
59+
pip install poetry
60+
poetry install --no-interaction
61+
- name: Run smoke tests
62+
run: |
63+
poetry run pytest -m "micro" --maxfail=1 --tb=no -q --timeout=30
64+
timeout-minutes: 3
65+
66+
# Main test matrix
67+
test-matrix:
68+
runs-on: ubuntu-latest
69+
needs: [smoke-test]
70+
if: always() && (needs.smoke-test.result == 'success' || github.event_name != 'pull_request')
3371
strategy:
72+
fail-fast: false
3473
matrix:
35-
python-version: [3.11]
74+
python-version: ["3.9", "3.10", "3.11"]
75+
test-group: ["unit", "integration", "layers"]
76+
include:
77+
- python-version: "3.11"
78+
test-group: "processor"
79+
- python-version: "3.11"
80+
test-group: "time-series"
81+
82+
steps:
83+
- uses: actions/checkout@v4
84+
- name: Set up Python ${{ matrix.python-version }}
85+
uses: actions/setup-python@v4
86+
with:
87+
python-version: ${{ matrix.python-version }}
88+
89+
- name: Cache Poetry dependencies
90+
uses: actions/cache@v3
91+
with:
92+
path: |
93+
~/.cache/pypoetry
94+
~/.cache/pip
95+
key: ${{ runner.os }}-poetry-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }}
96+
restore-keys: |
97+
${{ runner.os }}-poetry-${{ matrix.python-version }}-
98+
99+
- name: Install dependencies
100+
run: |
101+
python -m pip install --upgrade pip
102+
pip install poetry
103+
poetry install --no-interaction
104+
105+
- name: Run tests - ${{ matrix.test-group }}
106+
run: |
107+
case "${{ matrix.test-group }}" in
108+
"unit")
109+
poetry run pytest -c pytest-fast.ini -m "unit" --maxfail=10 --timeout=120
110+
;;
111+
"integration")
112+
poetry run pytest -m "integration" --maxfail=3 --timeout=300
113+
;;
114+
"layers")
115+
poetry run pytest -c pytest-fast.ini -m "layers" --maxfail=5 --timeout=120
116+
;;
117+
"processor")
118+
poetry run pytest -c pytest-fast.ini -m "processor" --maxfail=3 --timeout=180
119+
;;
120+
"time-series")
121+
poetry run pytest -c pytest-fast.ini -m "time_series" --maxfail=3 --timeout=180
122+
;;
123+
esac
124+
timeout-minutes: 8
125+
126+
- name: Upload test results
127+
uses: actions/upload-artifact@v3
128+
if: always()
129+
with:
130+
name: test-results-${{ matrix.python-version }}-${{ matrix.test-group }}
131+
path: |
132+
pytest.xml
133+
htmlcov/
134+
retention-days: 7
135+
136+
# Coverage job (only on main Python version)
137+
coverage:
138+
runs-on: ubuntu-latest
139+
needs: [test-matrix]
140+
if: always() && needs.test-matrix.result == 'success'
36141
steps:
37-
- uses: actions/checkout@v3
38-
- name: "running unit-tests"
39-
uses: "piotrlaczkowski/keras-data-processor/.github/templates/Python/unittests@main"
142+
- uses: actions/checkout@v4
143+
- name: Set up Python
144+
uses: actions/setup-python@v4
145+
with:
146+
python-version: "3.11"
147+
148+
- name: Install dependencies
149+
run: |
150+
python -m pip install --upgrade pip
151+
pip install poetry
152+
poetry install --no-interaction
153+
154+
- name: Run tests with coverage
155+
run: |
156+
poetry run pytest -c pytest-fast.ini --cov=kdp --cov-report=xml --cov-report=html --timeout=180
157+
timeout-minutes: 10
158+
159+
- name: Upload coverage to Codecov
160+
uses: codecov/codecov-action@v3
161+
with:
162+
file: ./coverage.xml
163+
flags: unittests
164+
name: codecov-umbrella
165+
fail_ci_if_error: false
166+
167+
- name: Upload coverage report
168+
uses: actions/upload-artifact@v3
169+
with:
170+
name: coverage-report
171+
path: htmlcov/
172+
retention-days: 30
173+
174+
# Performance benchmark job (optional)
175+
benchmark:
176+
runs-on: ubuntu-latest
177+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
178+
steps:
179+
- uses: actions/checkout@v4
180+
- name: Set up Python
181+
uses: actions/setup-python@v4
182+
with:
183+
python-version: "3.11"
184+
185+
- name: Install dependencies
186+
run: |
187+
python -m pip install --upgrade pip
188+
pip install poetry
189+
poetry install --no-interaction
190+
191+
- name: Run benchmarks
192+
run: |
193+
poetry run pytest -m "performance" --benchmark-only --benchmark-json=benchmark.json || true
194+
timeout-minutes: 10
195+
196+
- name: Upload benchmark results
197+
uses: actions/upload-artifact@v3
198+
if: always()
40199
with:
41-
pkg_folder: "kdp"
42-
PYTHON_VERSION: ${{ matrix.python-version }}
200+
name: benchmark-results
201+
path: benchmark.json
202+
retention-days: 30

Makefile

Lines changed: 97 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,112 @@ POETRY_VERSION := $(shell poetry version $(shell git describe --tags --abbrev=0)
99
# Test
1010
# ------------------------------------
1111

12+
.PHONY: test
13+
## Run ALL tests in parallel with optimizations
14+
test:
15+
poetry run pytest -c pytest-fast.ini
16+
17+
.PHONY: test-fast
18+
## Run only fast tests in parallel
19+
test-fast:
20+
poetry run pytest -m "fast or unit" --maxfail=5
21+
22+
.PHONY: test-all
23+
## Run ALL tests (unit, integration, layers, everything) with optimizations
24+
test-all:
25+
poetry run pytest -c pytest-fast.ini --cov=kdp --cov-report=term-missing --cov-report=html
26+
27+
.PHONY: test-slow
28+
## Run slow and integration tests
29+
test-slow:
30+
poetry run pytest -m "slow or integration" --maxfail=3
31+
32+
.PHONY: test-unit
33+
## Run unit tests only
34+
test-unit:
35+
poetry run pytest -m "unit" --maxfail=10
36+
37+
.PHONY: test-integration
38+
## Run integration tests only
39+
test-integration:
40+
poetry run pytest -m "integration" --maxfail=3
41+
42+
.PHONY: test-layers
43+
## Run layer-specific tests
44+
test-layers:
45+
poetry run pytest -m "layers" --maxfail=5
46+
47+
.PHONY: test-processor
48+
## Run processor-specific tests
49+
test-processor:
50+
poetry run pytest -m "processor" --maxfail=3
51+
52+
.PHONY: test-time-series
53+
## Run time series tests
54+
test-time-series:
55+
poetry run pytest -m "time_series" --maxfail=3
56+
57+
.PHONY: test-sequential
58+
## Run tests sequentially (no parallel execution)
59+
test-sequential:
60+
poetry run pytest -n 0
61+
62+
.PHONY: test-verbose
63+
## Run tests with verbose output
64+
test-verbose:
65+
poetry run pytest -v --tb=long
66+
67+
.PHONY: test-benchmark
68+
## Run performance benchmark tests
69+
test-benchmark:
70+
poetry run pytest -m "performance" --benchmark-only
71+
72+
.PHONY: test-smoke
73+
## Run a quick smoke test (fastest tests only)
74+
test-smoke:
75+
poetry run pytest -m "fast" --maxfail=1 --tb=no -q
76+
77+
.PHONY: test-ultrafast
78+
## Run tests with ultra-fast configuration (may be unstable)
79+
test-ultrafast:
80+
poetry run pytest -c pytest-ultrafast.ini
81+
82+
.PHONY: test-fast-balanced
83+
## Run tests with balanced fast configuration
84+
test-fast-balanced:
85+
poetry run pytest -c pytest-fast.ini
86+
87+
.PHONY: test-micro
88+
## Run only micro tests (fastest possible)
89+
test-micro:
90+
poetry run pytest -m "micro" --maxfail=1 --tb=no -q --timeout=30
91+
92+
.PHONY: test-parallel-max
93+
## Run tests with maximum parallelization
94+
test-parallel-max:
95+
poetry run pytest -n logical --maxfail=3 --tb=no -q --timeout=90
96+
1297
.PHONY: unittests
13-
## Run unittests
14-
unittests:
15-
poetry run python -m pytest
98+
## Run unittests (legacy command, use 'test' instead)
99+
unittests: test
16100

17101
.PHONY: clean_tests
18-
## Remove pytest cache and junit report after tests
102+
## Remove pytest cache and test artifacts
19103
clean_tests:
20104
find . -type d -name .pytest_cache -exec rm -r {} +
105+
find . -type d -name __pycache__ -exec rm -r {} +
21106
find . -type f -name '*junit_report.xml' -exec rm {} +
107+
find . -type f -name '*.pyc' -exec rm {} +
108+
rm -rf htmlcov/
109+
rm -f .coverage
110+
rm -f coverage.xml
111+
rm -f pytest.xml
22112

23113
.PHONY: coverage
24-
## Combine and build final coverage
114+
## Generate coverage report
25115
coverage:
26-
coverage run -m pytest
27-
coverage combine --data-file .coverage || true
28-
coverage html -i
29-
coverage report -i
116+
poetry run pytest --cov-report=html --cov-report=term-missing
117+
@echo "Coverage report generated in htmlcov/index.html"
30118

31119
# ------------------------------------
32120
# Build package

0 commit comments

Comments
 (0)