Skip to content

Commit f38601f

Browse files
committed
try to log skipped tests
1 parent decec94 commit f38601f

File tree

2 files changed

+156
-0
lines changed

2 files changed

+156
-0
lines changed

.github/workflows/ci.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ jobs:
5959
permissions:
6060
id-token: write # This is required for requesting the JWT
6161
steps:
62+
- uses: actions/checkout@v4
63+
with:
64+
submodules: true
6265
- name: configure AWS credentials (containers)
6366
uses: aws-actions/configure-aws-credentials@v4
6467
with:
@@ -68,6 +71,14 @@ jobs:
6871
run: |
6972
aws s3 cp s3://aws-crt-test-stuff/ci/${{ env.BUILDER_VERSION }}/linux-container-ci.sh ./linux-container-ci.sh && chmod a+x ./linux-container-ci.sh
7073
./linux-container-ci.sh ${{ env.BUILDER_VERSION }} aws-crt-manylinux2014-${{ matrix.image }} build -p ${{ env.PACKAGE_NAME }} --python /opt/python/${{ matrix.python }}/bin/python
74+
- name: Track skipped tests
75+
run: |
76+
if [ -d ".venv-builder" ]; then
77+
source .venv-builder/bin/activate
78+
python scripts/test_runner.py --top-level-directory . --verbose --start-directory test 2>/dev/null | grep -A 1000 "SKIPPED TESTS SUMMARY" || echo "No skipped tests found or test runner not available"
79+
else
80+
echo "Virtual environment not found, skipping skipped test tracking"
81+
fi
7182
7283
manylinux2014-arm64:
7384
runs-on: ubuntu-24.04-arm
@@ -84,6 +95,9 @@ jobs:
8495
permissions:
8596
id-token: write # This is required for requesting the JWT
8697
steps:
98+
- uses: actions/checkout@v4
99+
with:
100+
submodules: true
87101
- name: configure AWS credentials (containers)
88102
uses: aws-actions/configure-aws-credentials@v4
89103
with:
@@ -93,6 +107,14 @@ jobs:
93107
run: |
94108
aws s3 cp s3://aws-crt-test-stuff/ci/${{ env.BUILDER_VERSION }}/linux-container-ci.sh ./linux-container-ci.sh && chmod a+x ./linux-container-ci.sh
95109
./linux-container-ci.sh ${{ env.BUILDER_VERSION }} aws-crt-manylinux2014-aarch64 build -p ${{ env.PACKAGE_NAME }} --python /opt/python/${{ matrix.python }}/bin/python
110+
- name: Track skipped tests
111+
run: |
112+
if [ -d ".venv-builder" ]; then
113+
source .venv-builder/bin/activate
114+
python scripts/test_runner.py --top-level-directory . --verbose --start-directory test 2>/dev/null | grep -A 1000 "SKIPPED TESTS SUMMARY" || echo "No skipped tests found or test runner not available"
115+
else
116+
echo "Virtual environment not found, skipping skipped test tracking"
117+
fi
96118
97119
musllinux-1-1:
98120
runs-on: ubuntu-24.04 # latest
@@ -226,6 +248,9 @@ jobs:
226248
permissions:
227249
id-token: write # This is required for requesting the JWT
228250
steps:
251+
- uses: actions/checkout@v4
252+
with:
253+
submodules: true
229254
- name: configure AWS credentials (containers)
230255
uses: aws-actions/configure-aws-credentials@v4
231256
with:
@@ -249,6 +274,15 @@ jobs:
249274
250275
USES_LIBCRYPTO_SO=`echo "$LINKED_AGAINST" | grep 'libcrypto*.so' | head -1`
251276
test -n "$USES_LIBCRYPTO_SO"
277+
- name: Track skipped tests
278+
run: |
279+
if [ -d "aws-crt-python/.venv-builder" ]; then
280+
cd aws-crt-python
281+
source .venv-builder/bin/activate
282+
python ../scripts/test_runner.py --top-level-directory . --verbose --start-directory test 2>/dev/null | grep -A 1000 "SKIPPED TESTS SUMMARY" || echo "No skipped tests found or test runner not available"
283+
else
284+
echo "Virtual environment not found, skipping skipped test tracking"
285+
fi
252286
253287
windows:
254288
# Currently, setup.py explicitly tries to use Windows SDK 10.0.17763.0.

scripts/test_runner.py

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#!/usr/bin/env python3
2+
3+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
# SPDX-License-Identifier: Apache-2.0.
5+
6+
"""
7+
Custom test runner that tracks and reports skipped tests.
8+
"""
9+
10+
import sys
11+
import unittest
12+
import argparse
13+
from io import StringIO
14+
15+
16+
class SkippedTestTracker(unittest.TextTestResult):
17+
"""Custom test result that tracks skipped tests with their reasons."""
18+
19+
def __init__(self, stream, descriptions, verbosity):
20+
super().__init__(stream, descriptions, verbosity)
21+
self.skipped_tests = []
22+
23+
def addSkip(self, test, reason):
24+
"""Override to track skipped tests."""
25+
super().addSkip(test, reason)
26+
self.skipped_tests.append({
27+
'test': str(test),
28+
'reason': reason,
29+
'class': test.__class__.__name__,
30+
'method': test._testMethodName
31+
})
32+
33+
34+
class SkippedTestRunner(unittest.TextTestRunner):
35+
"""Custom test runner that uses our SkippedTestTracker."""
36+
37+
def __init__(self, stream=None, descriptions=True, verbosity=1,
38+
failfast=False, buffer=False, resultclass=None, warnings=None, *, tb_locals=False):
39+
if resultclass is None:
40+
resultclass = SkippedTestTracker
41+
super().__init__(stream, descriptions, verbosity, failfast, buffer,
42+
resultclass, warnings, tb_locals=tb_locals)
43+
44+
def run(self, test):
45+
"""Run tests and report skipped tests at the end."""
46+
result = super().run(test)
47+
48+
# Print summary of skipped tests
49+
if hasattr(result, 'skipped_tests') and result.skipped_tests:
50+
self.stream.write('\n' + '='*70 + '\n')
51+
self.stream.write(f'SKIPPED TESTS SUMMARY ({len(result.skipped_tests)} total)\n')
52+
self.stream.write('='*70 + '\n')
53+
54+
# Group by class for better organization
55+
by_class = {}
56+
for skip in result.skipped_tests:
57+
class_name = skip['class']
58+
if class_name not in by_class:
59+
by_class[class_name] = []
60+
by_class[class_name].append(skip)
61+
62+
for class_name, skips in sorted(by_class.items()):
63+
self.stream.write(f'\n{class_name}:\n')
64+
for skip in skips:
65+
self.stream.write(f' - {skip["method"]}: {skip["reason"]}\n')
66+
67+
self.stream.write('\n' + '='*70 + '\n')
68+
else:
69+
self.stream.write('\nNo tests were skipped.\n')
70+
71+
return result
72+
73+
74+
def main():
75+
"""Main entry point for the custom test runner."""
76+
parser = argparse.ArgumentParser(description='Run tests with skipped test tracking')
77+
parser.add_argument('--start-directory', '-s', default='test',
78+
help='Directory to start discovery (default: test)')
79+
parser.add_argument('--pattern', '-p', default='test*.py',
80+
help='Pattern to match test files (default: test*.py)')
81+
parser.add_argument('--top-level-directory', '-t', default=None,
82+
help='Top level directory of project')
83+
parser.add_argument('--verbose', '-v', action='count', default=1,
84+
help='Verbose output (can be used multiple times)')
85+
parser.add_argument('--failfast', '-f', action='store_true',
86+
help='Stop on first failure')
87+
parser.add_argument('--buffer', '-b', action='store_true',
88+
help='Buffer stdout and stderr during tests')
89+
90+
args = parser.parse_args()
91+
92+
# Discover tests
93+
loader = unittest.TestLoader()
94+
95+
try:
96+
suite = loader.discover(
97+
start_dir=args.start_directory,
98+
pattern=args.pattern,
99+
top_level_dir=args.top_level_directory
100+
)
101+
except ImportError as e:
102+
print(f"Error discovering tests: {e}")
103+
return 1
104+
105+
# Run tests with our custom runner
106+
runner = SkippedTestRunner(
107+
verbosity=args.verbose,
108+
failfast=args.failfast,
109+
buffer=args.buffer
110+
)
111+
112+
result = runner.run(suite)
113+
114+
# Return appropriate exit code
115+
if result.wasSuccessful():
116+
return 0
117+
else:
118+
return 1
119+
120+
121+
if __name__ == '__main__':
122+
sys.exit(main())

0 commit comments

Comments
 (0)