Skip to content

Commit

Permalink
5 seconds for system tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stan-dot committed Feb 4, 2025
1 parent 229f472 commit 395146b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
19 changes: 14 additions & 5 deletions .github/scripts/check_test_durations.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
import json
import sys

THRESHOLD = 1.0 # seconds
# Get report filename and threshold from command-line arguments
REPORT_FILE = sys.argv[1] if len(sys.argv) > 1 else "report.json"
THRESHOLD = float(sys.argv[2]) if len(sys.argv) > 2 else 1.0

with open("report.json") as f:
data = json.load(f)
try:
with open(REPORT_FILE) as f:
data = json.load(f)
except FileNotFoundError:
print(f"❌ Error: Report file '{REPORT_FILE}' not found.")
sys.exit(1)
except json.JSONDecodeError:
print(f"❌ Error: Failed to parse JSON in '{REPORT_FILE}'.")
sys.exit(1)

slow_tests = [
(t["nodeid"], t["call"]["duration"])
for t in data["tests"]
for t in data.get("tests", [])
if "call" in t and t["call"]["duration"] > THRESHOLD
]

if slow_tests:
print("❌ The following tests exceeded the 1s threshold:")
print(f"❌ The following tests exceeded the {THRESHOLD:.2f}s threshold:")
for test, duration in slow_tests:
print(f" - {test}: {duration:.2f}s")
sys.exit(1)
Expand Down
14 changes: 10 additions & 4 deletions .github/workflows/_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,19 @@ jobs:
python-version: ${{ inputs.python-version }}
pip-install: ".[dev]"

- name: Run tests
run: tox -e report
- name: Run unit tests
run: tox -e unit-report

- name: Check test durations
- name: Check unit test durations
run: |
python .github/scripts/check_test_durations.py
python .github/scripts/check_test_durations.py unit-report.json 1
- name: Run system tests
run: tox -e system-report

- name: Check system test durations
run: |
python .github/scripts/check_test_durations.py system-report.json 5
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ commands =
type-checking: pyright src tests {posargs}
pre-commit: pre-commit run --all-files --show-diff-on-failure {posargs}
docs: sphinx-{posargs:build -E} -T docs build/html
report: pytest -m 'not (s03 or adsim)' --cov=dodal --cov-report term --cov-report xml:cov.xml --json-report --json-report-file=report.json {posargs}
unit-report: pytest -m 'not (s03 or adsim)' --cov=dodal --cov-report term --cov-report xml:cov.xml --json-report --json-report-file=unit-report.json tests {posargs}
system-report: pytest -m 'not (s03 or adsim)' --cov=dodal --cov-report term --cov-report xml:cov.xml --json-report --json-report-file=system-report.json system_tests {posargs}
"""

[tool.ruff]
Expand Down

0 comments on commit 395146b

Please sign in to comment.