From 4e042379fa74bfbc7aaafd27c1af05916508f0b7 Mon Sep 17 00:00:00 2001 From: Nityahapani Date: Sat, 1 Aug 2026 16:54:30 +0000 Subject: [PATCH] Add demo test for multioutput_reduced_gradient.py test_demos.py runs most demo scripts as a real subprocess smoke test. multioutput_reduced_gradient.py had no coverage; this is the only thing exercising xgboost.objective.TreeObjective at all (grepped tests/python/*.py for both the script name and TreeObjective directly -- zero hits either way), so this is genuinely the sole safety net for that experimental feature, not just a routine smoke test. Verified this is a real gap and not another false positive like my earlier mistake with prediction_intervals.py: re-ran the demo-vs-test comparison from scratch on a clean master checkout with a more robust grep pattern, and separately grepped the test file directly for both the script's filename and its actual class names (TreeObjective, LsObjMean, LsObjSvd) to be sure. Runs with the script's default `--device cpu` (no args needed). Its three `import cupy` statements are all inside `else` branches gated on `self.device == "cpu"` checks (confirmed by reading each one's surrounding context directly), so none of them execute on this path -- no cupy/GPU dependency for this test. `no_sklearn()` skip marker matches every other sklearn-dependent test in this file (the script uses sklearn.datasets.make_regression, sklearn.base.BaseEstimator, and sklearn.decomposition.TruncatedSVD, all part of core scikit-learn, no extra dependency). --- tests/python/test_demos.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/python/test_demos.py b/tests/python/test_demos.py index 0faff4a73570..c4e4db4b5b7f 100644 --- a/tests/python/test_demos.py +++ b/tests/python/test_demos.py @@ -165,6 +165,15 @@ def test_multioutput_reg() -> None: subprocess.check_call(cmd) +@pytest.mark.skipif(**tm.no_sklearn()) +def test_multioutput_reduced_gradient_demo() -> None: + # Runs with the default `--device cpu`; `cupy` is only imported on the + # (unused here) `--device cuda` code paths. + script = os.path.join(PYTHON_DEMO_DIR, "multioutput_reduced_gradient.py") + cmd = [PYTHON, script] + subprocess.check_call(cmd) + + @pytest.mark.skipif(**tm.no_sklearn()) def test_prediction_intervals() -> None: script = os.path.join(PYTHON_DEMO_DIR, "prediction_intervals.py")