@@ -180,51 +180,89 @@ jobs:
180
180
echo "allowlist_externals =" >> tox_pr.ini
181
181
echo " pytest" >> tox_pr.ini
182
182
echo " coverage" >> tox_pr.ini
183
+ echo " python" >> tox_pr.ini
183
184
echo "commands =" >> tox_pr.ini
184
185
185
- # For tox, let's focus on integration tests and coverage only
186
- # to avoid duplicating what individual matrix jobs are doing
186
+ # Check if we have any implementation files that changed
187
+ pattern_files=0
188
+ test_files=0
187
189
188
- # Always run a baseline test with coverage
189
- echo " pytest -xvs --cov=patterns tests/ --cov-report=term-missing" >> tox_pr.ini
190
+ for file in $changed_files; do
191
+ if [[ $file == patterns/* ]]; then
192
+ pattern_files=1
193
+ elif [[ $file == tests/* ]]; then
194
+ test_files=1
195
+ fi
196
+ done
190
197
191
- # Add coverage-focused test commands
198
+ # Only run targeted tests, no baseline
192
199
echo " # Run specific tests for changed files" >> tox_pr.ini
200
+
201
+ has_tests=false
202
+
203
+ # Add coverage-focused test commands
193
204
for file in $changed_files; do
194
205
if [[ $file == *.py ]]; then
195
206
# Run coverage tests for implementation files
196
207
if [[ $file == patterns/* ]]; then
197
208
module_name=$(basename $file .py)
198
- pattern_dir=$(dirname $file | cut -d'/' -f2)
209
+
210
+ # Get the pattern type (behavioral, structural, etc.)
211
+ if [[ $file == patterns/behavioral/* ]]; then
212
+ pattern_dir="behavioral"
213
+ elif [[ $file == patterns/creational/* ]]; then
214
+ pattern_dir="creational"
215
+ elif [[ $file == patterns/structural/* ]]; then
216
+ pattern_dir="structural"
217
+ elif [[ $file == patterns/fundamental/* ]]; then
218
+ pattern_dir="fundamental"
219
+ elif [[ $file == patterns/other/* ]]; then
220
+ pattern_dir="other"
221
+ else
222
+ pattern_dir=""
223
+ fi
224
+
199
225
echo " # Testing $file" >> tox_pr.ini
200
226
201
- # Run appropriate tests for this module
202
- echo " python -c \"import os.path; test_path='tests/${pattern_dir}/test_${module_name}.py'; print(f'Test file {test_path} exists: {os.path.exists(test_path)}')\"" >> tox_pr.ini
203
- echo " pytest -xvs --cov=patterns --cov-append tests/${pattern_dir}/ -k \"${module_name}\"" >> tox_pr.ini
227
+ # Check if specific test exists
228
+ if [ -n "$pattern_dir" ]; then
229
+ test_path="tests/${pattern_dir}/test_${module_name}.py"
230
+ echo " python -c \"import os.path; test_path='${test_path}'; exists=os.path.exists(test_path); print(f'Test file {test_path} exists: {exists}'); exit(0 if exists else 1)\" && pytest -xvs --cov=patterns --cov-append ${test_path}" >> tox_pr.ini || true
231
+
232
+ # Also try to find any test that might include this module
233
+ echo " pytest -xvs --cov=patterns --cov-append tests/${pattern_dir}/ -k \"${module_name}\" --no-header" >> tox_pr.ini
234
+ fi
235
+
236
+ # Run doctests for the file
237
+ echo " pytest --doctest-modules -v --cov=patterns --cov-append $file" >> tox_pr.ini
238
+
239
+ has_tests=true
204
240
fi
205
241
206
242
# Run test files directly if modified
207
243
if [[ $file == tests/* ]]; then
208
244
echo " pytest -xvs --cov=patterns --cov-append $file" >> tox_pr.ini
245
+ has_tests=true
209
246
fi
210
247
fi
211
248
done
212
249
213
- # Run doctests on pattern files
214
- echo " # Run doctests" >> tox_pr.ini
215
- for file in $changed_files; do
216
- if [[ $file == patterns/*.py ]]; then
217
- echo " pytest --doctest-modules -v --cov=patterns --cov-append $file" >> tox_pr.ini
218
- fi
219
- done
250
+ # If we didn't find any specific tests to run, mention it
251
+ if [ "$has_tests" = false ]; then
252
+ echo " python -c \"print('No specific tests found for changed files. Consider adding tests.')\"" >> tox_pr.ini
253
+ # Add a minimal test to avoid failure
254
+ echo " pytest -xk \"not integration\" --no-header" >> tox_pr.ini
255
+ fi
220
256
221
257
# Add coverage report command
222
258
echo " coverage combine" >> tox_pr.ini
223
259
echo " coverage report" >> tox_pr.ini
224
260
225
261
# Run tox with the custom configuration
226
262
echo "Running tox with custom PR configuration..."
263
+ echo "======================== TOX CONFIG ========================"
227
264
cat tox_pr.ini
265
+ echo "==========================================================="
228
266
tox -c tox_pr.ini
229
267
230
268
summary :
0 commit comments