Skip to content

Commit 23f4a16

Browse files
Add one second test check to CI (#1033)
* add one second test check to CI * pyproject add tests-report as an available testenv * fix typo * exclude the option of tox parsing weird * 5 seconds for system tests * tox is a pain * add two different codecov file names --------- Co-authored-by: Dominic Oram <[email protected]>
1 parent 81496ff commit 23f4a16

File tree

4 files changed

+52
-4
lines changed

4 files changed

+52
-4
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import json
2+
import sys
3+
4+
# Get report filename and threshold from command-line arguments
5+
REPORT_FILE = sys.argv[1] if len(sys.argv) > 1 else "report.json"
6+
THRESHOLD = float(sys.argv[2]) if len(sys.argv) > 2 else 1.0
7+
8+
try:
9+
with open(REPORT_FILE) as f:
10+
data = json.load(f)
11+
except FileNotFoundError:
12+
print(f"❌ Error: Report file '{REPORT_FILE}' not found.")
13+
sys.exit(1)
14+
except json.JSONDecodeError:
15+
print(f"❌ Error: Failed to parse JSON in '{REPORT_FILE}'.")
16+
sys.exit(1)
17+
18+
slow_tests = [
19+
(t["nodeid"], t["call"]["duration"])
20+
for t in data.get("tests", [])
21+
if "call" in t and t["call"]["duration"] > THRESHOLD
22+
]
23+
24+
if slow_tests:
25+
print(f"❌ The following tests exceeded the {THRESHOLD:.2f}s threshold:")
26+
for test, duration in slow_tests:
27+
print(f" - {test}: {duration:.2f}s")
28+
sys.exit(1)
29+
30+
print("✅ All tests ran within the acceptable time limit.")

.github/workflows/_test.yml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,24 @@ jobs:
5050
python-version: ${{ inputs.python-version }}
5151
pip-install: ".[dev]"
5252

53-
- name: Run tests
54-
run: tox -e tests
53+
- name: Run unit tests
54+
run: tox -e unit-report
55+
56+
- name: Check unit test durations
57+
run: |
58+
python .github/scripts/check_test_durations.py unit-report.json 1
59+
60+
- name: Run system tests
61+
run: tox -e system-report
62+
63+
- name: Check system test durations
64+
run: |
65+
python .github/scripts/check_test_durations.py system-report.json 5
5566
5667
- name: Upload coverage to Codecov
5768
uses: codecov/codecov-action@v4
5869
with:
5970
name: ${{ inputs.python-version }}/${{ inputs.runs-on }}
60-
files: cov.xml
71+
files: ./unit_cov.xml,./system_cov.xml
6172
env:
6273
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,7 @@ lockfiles/
7474

7575
# pycharm project files
7676
.idea/
77+
78+
79+
# custom CI setup
80+
report.json

pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ dev = [
5858
"pytest",
5959
"pytest-asyncio",
6060
"pytest-cov",
61+
"pytest-json-report",
6162
"pytest-random-order",
6263
"ruff",
6364
"sphinx<7.4.6", # pinned due to https://github.com/sphinx-doc/sphinx/issues/12660
@@ -141,7 +142,7 @@ legacy_tox_ini = """
141142
[tox]
142143
skipsdist=True
143144
144-
[testenv:{pre-commit,type-checking,tests,docs}]
145+
[testenv:{pre-commit,type-checking,tests,docs,unit-report,system-report}]
145146
# Don't create a virtualenv for the command, requires tox-direct plugin
146147
direct = True
147148
passenv = *
@@ -156,6 +157,8 @@ commands =
156157
type-checking: pyright src tests {posargs}
157158
pre-commit: pre-commit run --all-files --show-diff-on-failure {posargs}
158159
docs: sphinx-{posargs:build -E} -T docs build/html
160+
unit-report: pytest -m 'not (s03 or adsim)' --cov=dodal --cov-report term --cov-report xml:unit_cov.xml --json-report --json-report-file=unit-report.json tests {posargs}
161+
system-report: pytest -m 'not (s03 or adsim)' --cov=dodal --cov-report term --cov-report xml:system_cov.xml --json-report --json-report-file=system-report.json system_tests {posargs}
159162
"""
160163

161164
[tool.ruff]

0 commit comments

Comments
 (0)