Skip to content

Commit 06b5112

Browse files
Add pytest markers and improve test categorization for GitHub workflow
Co-authored-by: piotr.laczkowski <piotr.laczkowski@gmail.com>
1 parent a700bad commit 06b5112

File tree

5 files changed

+195
-0
lines changed

5 files changed

+195
-0
lines changed

GITHUB_WORKFLOW_FIXES.md

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
# GitHub Workflow Test Fixes
2+
3+
## Issues Identified and Fixed
4+
5+
### 1. Missing Pytest Markers
6+
7+
**Problem**: The GitHub Actions workflow uses pytest markers to categorize and run different types of tests, but some tests were missing the required markers.
8+
9+
**Solution**: Added appropriate pytest markers to all test classes and methods:
10+
11+
#### Added to Test Classes:
12+
- `@pytest.mark.layers` - For layer-specific tests
13+
- `@pytest.mark.unit` - For unit tests
14+
- `@pytest.mark.fast` - For fast-running tests
15+
- `@pytest.mark.micro` - For micro tests (fastest)
16+
- `@pytest.mark.processor` - For processor-specific tests
17+
- `@pytest.mark.integration` - For integration tests
18+
19+
#### Files Modified:
20+
- `test/layers/test_preserve_dtype_layer.py`
21+
- `test/layers/test_layer_factory.py`
22+
- `test/test_processor.py`
23+
24+
### 2. Missing Micro Marker
25+
26+
**Problem**: The smoke test in the GitHub Actions workflow runs tests with the `micro` marker, but no tests had this marker.
27+
28+
**Solution**:
29+
- Added `micro` marker to the pytest configuration in `pytest.ini`
30+
- Added `@pytest.mark.micro` to the fastest tests:
31+
- `TestPreserveDtypeLayer` class
32+
- `TestPreprocessorLayerFactory` class
33+
- `test_preprocessor_with_passthrough_feature` method
34+
35+
### 3. Missing Pytest Import
36+
37+
**Problem**: Some test files were using pytest markers without importing pytest.
38+
39+
**Solution**: Added `import pytest` to `test/test_processor.py`
40+
41+
### 4. Test Categorization
42+
43+
**Problem**: Tests needed to be properly categorized for the GitHub Actions matrix to run them correctly.
44+
45+
**Solution**: Ensured all tests have the correct markers:
46+
- **Layer tests**: `@pytest.mark.layers` + `@pytest.mark.unit` + `@pytest.mark.fast` + `@pytest.mark.micro`
47+
- **Processor tests**: `@pytest.mark.processor` + `@pytest.mark.integration`
48+
- **Integration tests**: `@pytest.mark.integration`
49+
50+
## GitHub Actions Workflow Analysis
51+
52+
### Workflow Structure:
53+
1. **Smoke Test**: Runs `pytest -m "micro"` for quick feedback
54+
2. **Test Matrix**: Runs different test groups on different Python versions
55+
3. **Coverage**: Runs full test suite with coverage reporting
56+
57+
### Test Groups:
58+
- `unit`: Unit tests with `--maxfail=10 --timeout=120`
59+
- `integration`: Integration tests with `--maxfail=3 --timeout=300`
60+
- `layers`: Layer tests with `--maxfail=5 --timeout=120`
61+
- `processor`: Processor tests with `--maxfail=3 --timeout=180`
62+
- `time-series`: Time series tests with `--maxfail=3 --timeout=180`
63+
64+
### Python Versions:
65+
- 3.9, 3.10, 3.11 (main matrix)
66+
- 3.11 (processor and time-series tests)
67+
68+
## Files Modified for Workflow Compatibility
69+
70+
### 1. Test Files
71+
- `test/layers/test_preserve_dtype_layer.py`
72+
- Added pytest markers: `layers`, `unit`, `fast`, `micro`
73+
- Added comprehensive test coverage for PreserveDtypeLayer
74+
75+
- `test/layers/test_layer_factory.py`
76+
- Added pytest markers: `layers`, `unit`, `fast`, `micro`
77+
- Added test for `preserve_dtype_layer` factory method
78+
79+
- `test/test_processor.py`
80+
- Added pytest import
81+
- Added pytest markers to all test classes
82+
- Added `micro` marker to fast passthrough tests
83+
- Added comprehensive passthrough feature tests
84+
85+
### 2. Configuration Files
86+
- `pytest.ini`
87+
- Added `micro` marker definition
88+
- Ensured all required markers are defined
89+
90+
### 3. Core Implementation Files
91+
- `kdp/layers/preserve_dtype.py` - New layer implementation
92+
- `kdp/layers_factory.py` - Added factory method
93+
- `kdp/processor.py` - Updated passthrough processing logic
94+
95+
## Test Coverage
96+
97+
### New Tests Added:
98+
1. **PreserveDtypeLayer Tests**:
99+
- `test_preserve_original_dtype`
100+
- `test_cast_to_target_dtype`
101+
- `test_string_to_other_types`
102+
- `test_batch_processing`
103+
- `test_serialization`
104+
- `test_model_integration`
105+
106+
2. **Factory Method Tests**:
107+
- `test_preserve_dtype_layer`
108+
109+
3. **Integration Tests**:
110+
- `test_passthrough_feature_preserves_string_dtype`
111+
- `test_passthrough_feature_preserves_int_dtype`
112+
- `test_passthrough_feature_preserves_float_dtype`
113+
- `test_passthrough_feature_mixed_types`
114+
115+
### Test Categories:
116+
- **Micro Tests**: Fastest tests for smoke testing
117+
- **Unit Tests**: Individual component tests
118+
- **Integration Tests**: End-to-end functionality tests
119+
- **Layer Tests**: Keras layer-specific tests
120+
- **Processor Tests**: Preprocessing pipeline tests
121+
122+
## Verification Steps
123+
124+
### 1. Syntax Validation
125+
All modified files pass Python syntax validation:
126+
- `kdp/layers/preserve_dtype.py`
127+
- `kdp/layers_factory.py`
128+
- `kdp/processor.py`
129+
- `test/layers/test_preserve_dtype_layer.py`
130+
- `test/layers/test_layer_factory.py`
131+
- `test/test_processor.py`
132+
133+
### 2. Marker Validation
134+
All test classes have appropriate pytest markers for GitHub Actions categorization.
135+
136+
### 3. Import Validation
137+
All necessary imports are present and correctly ordered.
138+
139+
## Expected Workflow Behavior
140+
141+
### Smoke Test (PR):
142+
- Runs `pytest -m "micro"`
143+
- Should complete in <3 minutes
144+
- Tests the fastest, most critical functionality
145+
146+
### Test Matrix:
147+
- **Unit Tests**: Run on Python 3.9, 3.10, 3.11
148+
- **Integration Tests**: Run on Python 3.9, 3.10, 3.11
149+
- **Layer Tests**: Run on Python 3.9, 3.10, 3.11
150+
- **Processor Tests**: Run on Python 3.11 only
151+
- **Time Series Tests**: Run on Python 3.11 only
152+
153+
### Coverage:
154+
- Runs on Python 3.11
155+
- Generates coverage reports
156+
- Uploads to Codecov
157+
158+
## Benefits
159+
160+
1. **Proper Test Categorization**: Tests are now properly categorized for efficient CI/CD
161+
2. **Fast Feedback**: Smoke tests provide quick feedback on PRs
162+
3. **Comprehensive Coverage**: All test types run on appropriate Python versions
163+
4. **Maintainable Structure**: Clear separation of test types and responsibilities
164+
5. **Reliable CI**: Tests should now pass consistently in GitHub Actions
165+
166+
## Next Steps
167+
168+
1. **Monitor Workflow Runs**: Watch GitHub Actions to ensure all tests pass
169+
2. **Add More Micro Tests**: Consider adding more micro tests for better smoke testing
170+
3. **Performance Optimization**: Monitor test execution times and optimize if needed
171+
4. **Coverage Improvement**: Ensure new code has adequate test coverage

pytest.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ markers =
2424
integration: Integration tests that may take longer
2525
slow: Tests that take a long time to run
2626
fast: Tests that run very quickly
27+
micro: Micro tests (fastest)
2728
time_series: Time series specific tests
2829
layers: Layer-specific tests
2930
processor: Processor-specific tests

test/layers/test_layer_factory.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
from kdp.layers.gated_residual_network_layer import GatedResidualNetwork
2727

2828

29+
@pytest.mark.layers
30+
@pytest.mark.unit
31+
@pytest.mark.fast
32+
@pytest.mark.micro
2933
class TestPreprocessorLayerFactory(unittest.TestCase):
3034
def setUp(self):
3135
# Set seeds for reproducibility

test/layers/test_preserve_dtype_layer.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
import unittest
22
import numpy as np
33
import tensorflow as tf
4+
import pytest
45

56
from kdp.layers.preserve_dtype import PreserveDtypeLayer
67

78

9+
@pytest.mark.layers
10+
@pytest.mark.unit
11+
@pytest.mark.fast
12+
@pytest.mark.micro
813
class TestPreserveDtypeLayer(unittest.TestCase):
914
"""Test cases for PreserveDtypeLayer."""
1015

test/test_processor.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import numpy as np
66
import pandas as pd
7+
import pytest
78
import tensorflow as tf
89

910
from kdp.layers.distribution_aware_encoder_layer import DistributionType
@@ -119,6 +120,8 @@ class instances (NumericalFeature, CategoricalFeature, TextFeature, DateFeature)
119120
return pd.DataFrame(data)
120121

121122

123+
@pytest.mark.unit
124+
@pytest.mark.fast
122125
class TestFeatureSpaceConverter(unittest.TestCase):
123126
def setUp(self):
124127
"""Setup test case environment."""
@@ -322,6 +325,8 @@ def test_init_features_specs_extended(self):
322325
self.assertEqual(feat9_instance.feature_type, FeatureType.DATE)
323326

324327

328+
@pytest.mark.processor
329+
@pytest.mark.integration
325330
class TestPreprocessingModel(unittest.TestCase):
326331
@classmethod
327332
def setUpClass(cls):
@@ -1628,6 +1633,8 @@ def test_preprocessor_all_features_with_distribution_types(self):
16281633
) # Periodic features add 2 additional dimensions (sin and cos)
16291634

16301635

1636+
@pytest.mark.processor
1637+
@pytest.mark.integration
16311638
class TestPreprocessingModel_Combinations(unittest.TestCase):
16321639
@classmethod
16331640
def setUpClass(cls):
@@ -1801,6 +1808,7 @@ def test_preprocessor_parameter_combinations(self):
18011808
) # (batch_size, feature_dim)
18021809
# You can add more specific checks for each feature if needed
18031810

1811+
@pytest.mark.micro
18041812
def test_preprocessor_with_passthrough_feature(self):
18051813
"""Test preprocessor with a passthrough feature."""
18061814
# Create features specs with a passthrough feature
@@ -2046,6 +2054,8 @@ def test_passthrough_feature_mixed_types(self):
20462054
)
20472055

20482056

2057+
@pytest.mark.processor
2058+
@pytest.mark.integration
20492059
class TestPreprocessingModel_åNumericalEmbedding(unittest.TestCase):
20502060
@classmethod
20512061
def setUpClass(cls):
@@ -2255,6 +2265,8 @@ def test_advanced_embedding_config_preservation(self):
22552265
)
22562266

22572267

2268+
@pytest.mark.processor
2269+
@pytest.mark.integration
22582270
class TestPreprocessingModel_GlobalNumericalEmbedding(unittest.TestCase):
22592271
@classmethod
22602272
def setUpClass(cls):
@@ -2722,6 +2734,8 @@ def test_batch_predict_parallel_functionality(self):
27222734
next(invalid_ppr.batch_predict(dataset))
27232735

27242736

2737+
@pytest.mark.processor
2738+
@pytest.mark.integration
27252739
class TestPreprocessingModel_FeatureMoE(unittest.TestCase):
27262740
@classmethod
27272741
def setUpClass(cls):

0 commit comments

Comments
 (0)