Skip to content

Commit 149d23c

Browse files
AbhishekAbhishek9639
authored andcommitted
[MNT] Diagnose and address long test runtimes (#1633)
- Add global per-test timeout (600s) to pytest config - CI: report all test durations (--durations=0) for diagnosis - CI: add explicit --timeout=600 to prevent hanging tests - Optimize verify_cache_state fixture: scope function -> module - Add scripts/profile_tests.sh for local duration profiling
1 parent e653ef6 commit 149d23c

4 files changed

Lines changed: 37 additions & 7 deletions

File tree

.github/workflows/test.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ jobs:
153153
marks="not production_server"
154154
fi
155155
156-
pytest -n 4 --durations=20 --dist load -sv $codecov -o log_cli=true -m "$marks"
156+
pytest -n 4 --durations=0 --timeout=600 --dist load -sv $codecov -o log_cli=true -m "$marks"
157157
158158
- name: Run tests on Ubuntu Production
159159
if: matrix.os == 'ubuntu-latest'
@@ -171,14 +171,14 @@ jobs:
171171
marks="production_server"
172172
fi
173173
174-
pytest -n 4 --durations=20 --dist load -sv $codecov -o log_cli=true -m "$marks"
174+
pytest -n 4 --durations=0 --timeout=600 --dist load -sv $codecov -o log_cli=true -m "$marks"
175175
176176
- name: Run tests on Windows
177177
if: matrix.os == 'windows-latest'
178178
env:
179179
OPENML_TEST_SERVER_ADMIN_KEY: ${{ secrets.OPENML_TEST_SERVER_ADMIN_KEY }}
180180
run: | # we need a separate step because of the bash-specific if-statement in the previous one.
181-
pytest -n 4 --durations=20 --dist load -sv --reruns 5 --reruns-delay 1 -m "not test_server"
181+
pytest -n 4 --durations=0 --timeout=600 --dist load -sv --reruns 5 --reruns-delay 1 -m "not test_server"
182182
183183
- name: Upload coverage
184184
if: matrix.code-cov && always()

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ log_level="DEBUG"
130130
testpaths = ["tests"]
131131
minversion = "7.0"
132132
xfail_strict = true
133+
timeout = 600
133134
filterwarnings=[
134135
"ignore:the matrix subclass:PendingDeprecationWarning"
135136
]

scripts/profile_tests.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
# Profile test durations to diagnose slow tests (Issue #1633)
3+
# Usage: ./scripts/profile_tests.sh [marker_filter]
4+
#
5+
# Examples:
6+
# ./scripts/profile_tests.sh # non-server tests
7+
# ./scripts/profile_tests.sh "production_server" # production server tests only
8+
# ./scripts/profile_tests.sh "sklearn" # sklearn tests only
9+
10+
set -euo pipefail
11+
12+
MARKER_FILTER="${1:-not production_server and not test_server}"
13+
14+
echo "=== OpenML Test Duration Profiler ==="
15+
echo "Marker filter: $MARKER_FILTER"
16+
echo "Timeout per test: 300s"
17+
echo ""
18+
19+
pytest \
20+
--durations=0 \
21+
--timeout=300 \
22+
-q \
23+
-m "$MARKER_FILTER" \
24+
2>&1 | tee test_durations_report.txt
25+
26+
echo ""
27+
echo "=== Report saved to test_durations_report.txt ==="

tests/conftest.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ def delete_remote_files(tracker, flow_names) -> None:
106106
if "flow" in tracker:
107107
to_sort = list(zip(tracker["flow"], flow_names))
108108
flow_deletion_order = [
109-
entity_id for entity_id, _ in sorted(to_sort, key=lambda x: len(x[1]), reverse=True)
109+
entity_id
110+
for entity_id, _ in sorted(to_sort, key=lambda x: len(x[1]), reverse=True)
110111
]
111112
tracker["flow"] = [flow_deletion_order[1] for flow_id, _ in flow_deletion_order]
112113

@@ -275,7 +276,7 @@ def test_apikey_v2() -> str:
275276
return openml.config.get_test_servers()[APIVersion.V2]["apikey"]
276277

277278

278-
@pytest.fixture(autouse=True, scope="function")
279+
@pytest.fixture(autouse=True, scope="module")
279280
def verify_cache_state(test_files_directory) -> Iterator[None]:
280281
assert_static_test_cache_correct(test_files_directory)
281282
yield
@@ -324,11 +325,12 @@ def with_test_cache(test_files_directory, request):
324325
openml.config.set_root_cache_directory(_root_cache_directory)
325326
if tmp_cache.exists():
326327
shutil.rmtree(tmp_cache)
327-
328+
328329

329330
@pytest.fixture
330331
def static_cache_dir():
331-
return Path(__file__).parent / "files"
332+
return Path(__file__).parent / "files"
333+
332334

333335
@pytest.fixture
334336
def workdir(tmp_path):

0 commit comments

Comments
 (0)