Skip to content

Commit 07243d1

Browse files
AbhishekAbhishek
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 7feb2a3 commit 07243d1

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
@@ -119,7 +119,7 @@ jobs:
119119
marks="not production_server and not test_server"
120120
fi
121121
122-
pytest -n 4 --durations=20 --dist load -sv $codecov -o log_cli=true -m "$marks"
122+
pytest -n 4 --durations=0 --timeout=600 --dist load -sv $codecov -o log_cli=true -m "$marks"
123123
124124
- name: Run tests on Ubuntu Production
125125
if: matrix.os == 'ubuntu-latest'
@@ -136,14 +136,14 @@ jobs:
136136
marks="production_server and not test_server"
137137
fi
138138
139-
pytest -n 4 --durations=20 --dist load -sv $codecov -o log_cli=true -m "$marks"
139+
pytest -n 4 --durations=0 --timeout=600 --dist load -sv $codecov -o log_cli=true -m "$marks"
140140
141141
- name: Run tests on Windows
142142
if: matrix.os == 'windows-latest'
143143
env:
144144
OPENML_TEST_SERVER_ADMIN_KEY: ${{ secrets.OPENML_TEST_SERVER_ADMIN_KEY }}
145145
run: | # we need a separate step because of the bash-specific if-statement in the previous one.
146-
pytest -n 4 --durations=20 --dist load -sv --reruns 5 --reruns-delay 1 -m "not test_server"
146+
pytest -n 4 --durations=0 --timeout=600 --dist load -sv --reruns 5 --reruns-delay 1 -m "not test_server"
147147
148148
- name: Check for files left behind by test
149149
if: matrix.os != 'windows-latest' && always()

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ version = {attr = "openml.__version__.__version__"}
129129
testpaths = ["tests"]
130130
minversion = "7.0"
131131
xfail_strict = true
132+
timeout = 600
132133
filterwarnings=[
133134
"ignore:the matrix subclass:PendingDeprecationWarning"
134135
]

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
@@ -105,7 +105,8 @@ def delete_remote_files(tracker, flow_names) -> None:
105105
if "flow" in tracker:
106106
to_sort = list(zip(tracker["flow"], flow_names))
107107
flow_deletion_order = [
108-
entity_id for entity_id, _ in sorted(to_sort, key=lambda x: len(x[1]), reverse=True)
108+
entity_id
109+
for entity_id, _ in sorted(to_sort, key=lambda x: len(x[1]), reverse=True)
109110
]
110111
tracker["flow"] = [flow_deletion_order[1] for flow_id, _ in flow_deletion_order]
111112

@@ -254,7 +255,7 @@ def test_api_key() -> str:
254255
return TestBase.user_key
255256

256257

257-
@pytest.fixture(autouse=True, scope="function")
258+
@pytest.fixture(autouse=True, scope="module")
258259
def verify_cache_state(test_files_directory) -> Iterator[None]:
259260
assert_static_test_cache_correct(test_files_directory)
260261
yield
@@ -295,11 +296,12 @@ def with_test_cache(test_files_directory, request):
295296
openml.config.set_root_cache_directory(_root_cache_directory)
296297
if tmp_cache.exists():
297298
shutil.rmtree(tmp_cache)
298-
299+
299300

300301
@pytest.fixture
301302
def static_cache_dir():
302-
return Path(__file__).parent / "files"
303+
return Path(__file__).parent / "files"
304+
303305

304306
@pytest.fixture
305307
def workdir(tmp_path):

0 commit comments

Comments
 (0)