From 2176e511fca72cf1ef3414d31e701bf69c26d569 Mon Sep 17 00:00:00 2001 From: Jiaming Yuan Date: Mon, 17 Oct 2022 23:06:10 +0800 Subject: [PATCH] Disable pytest-timeout for now. (#8348) --- python-package/xgboost/testing.py | 25 ++++++++++++++++++++- tests/python-gpu/test_gpu_linear.py | 9 +++++--- tests/python-gpu/test_gpu_pickling.py | 16 +++++++------ tests/python-gpu/test_gpu_prediction.py | 12 +++++----- tests/python-gpu/test_gpu_ranking.py | 18 +++++++++------ tests/python-gpu/test_gpu_updaters.py | 13 ++++++----- tests/python/test_data_iterator.py | 13 ++++++----- tests/python/test_demos.py | 9 +++++--- tests/python/test_linear.py | 10 +++++---- tests/python/test_openmp.py | 10 +++++---- tests/python/test_spark/test_spark_local.py | 3 ++- tests/python/test_with_dask.py | 3 ++- tests/python/test_with_sklearn.py | 24 ++++++++++---------- 13 files changed, 107 insertions(+), 58 deletions(-) diff --git a/python-package/xgboost/testing.py b/python-package/xgboost/testing.py index 9e1b54276..4a8a9acbf 100644 --- a/python-package/xgboost/testing.py +++ b/python-package/xgboost/testing.py @@ -2,7 +2,7 @@ import socket from platform import system -from typing import TypedDict +from typing import Any, TypedDict PytestSkip = TypedDict("PytestSkip", {"condition": bool, "reason": str}) @@ -39,3 +39,26 @@ def has_ipv6() -> bool: def skip_ipv6() -> PytestSkip: """PyTest skip mark for IPv6.""" return {"condition": not has_ipv6(), "reason": "IPv6 is required to be enabled."} + + +def timeout(sec: int, *args: Any, enable: bool = False, **kwargs: Any) -> Any: + """Make a pytest mark for the `pytest-timeout` package. + + Parameters + ---------- + sec : + Timeout seconds. + enable : + Control whether timeout should be applied, used for debugging. + + Returns + ------- + pytest.mark.timeout + """ + import pytest # pylint: disable=import-error + + # This is disabled for now due to regression caused by conflicts between federated + # learning build and the CI container environment. + if enable: + return pytest.mark.timeout(sec, *args, **kwargs) + return pytest.mark.timeout(None, *args, **kwargs) diff --git a/tests/python-gpu/test_gpu_linear.py b/tests/python-gpu/test_gpu_linear.py index 4ac1d481e..5cd63e514 100644 --- a/tests/python-gpu/test_gpu_linear.py +++ b/tests/python-gpu/test_gpu_linear.py @@ -1,12 +1,15 @@ import sys -from hypothesis import strategies, given, settings, assume, note + import pytest +from hypothesis import assume, given, note, settings, strategies + import xgboost as xgb +from xgboost import testing + sys.path.append("tests/python") import testing as tm - -pytestmark = pytest.mark.timeout(10) +pytestmark = testing.timeout(10) parameter_strategy = strategies.fixed_dictionaries({ 'booster': strategies.just('gblinear'), diff --git a/tests/python-gpu/test_gpu_pickling.py b/tests/python-gpu/test_gpu_pickling.py index fa414b569..4b321bece 100644 --- a/tests/python-gpu/test_gpu_pickling.py +++ b/tests/python-gpu/test_gpu_pickling.py @@ -1,21 +1,23 @@ '''Test model IO with pickle.''' -import pickle -import numpy as np -import subprocess -import os -import sys import json +import os +import pickle +import subprocess +import sys + +import numpy as np import pytest + import xgboost as xgb -from xgboost import XGBClassifier +from xgboost import XGBClassifier, testing sys.path.append("tests/python") import testing as tm model_path = './model.pkl' +pytestmark = testing.timeout(30) -pytestmark = pytest.mark.timeout(30) def build_dataset(): N = 10 diff --git a/tests/python-gpu/test_gpu_prediction.py b/tests/python-gpu/test_gpu_prediction.py index 7a60a634f..3dedb0637 100644 --- a/tests/python-gpu/test_gpu_prediction.py +++ b/tests/python-gpu/test_gpu_prediction.py @@ -1,11 +1,12 @@ import sys -import pytest import numpy as np -import xgboost as xgb +import pytest +from hypothesis import assume, given, settings, strategies from xgboost.compat import PANDAS_INSTALLED -from hypothesis import given, strategies, assume, settings +import xgboost as xgb +from xgboost import testing if PANDAS_INSTALLED: from hypothesis.extra.pandas import column, data_frames, range_indexes @@ -16,8 +17,8 @@ else: sys.path.append("tests/python") import testing as tm +from test_predict import run_predict_leaf # noqa from test_predict import run_threaded_predict # noqa -from test_predict import run_predict_leaf # noqa rng = np.random.RandomState(1994) @@ -32,7 +33,8 @@ predict_parameter_strategy = strategies.fixed_dictionaries({ 'num_parallel_tree': strategies.sampled_from([1, 4]), }) -pytestmark = pytest.mark.timeout(20) +pytestmark = testing.timeout(20) + class TestGPUPredict: def test_predict(self): diff --git a/tests/python-gpu/test_gpu_ranking.py b/tests/python-gpu/test_gpu_ranking.py index d3f1afc24..059d9325a 100644 --- a/tests/python-gpu/test_gpu_ranking.py +++ b/tests/python-gpu/test_gpu_ranking.py @@ -1,17 +1,21 @@ -import numpy as np -import xgboost -import os import itertools +import os import shutil +import sys import urllib.request import zipfile -import sys -import pytest + +import numpy as np + +import xgboost +from xgboost import testing + sys.path.append("tests/python") -import testing as tm # noqa +import testing as tm # noqa + +pytestmark = testing.timeout(10) -pytestmark = pytest.mark.timeout(10) class TestRanking: @classmethod diff --git a/tests/python-gpu/test_gpu_updaters.py b/tests/python-gpu/test_gpu_updaters.py index e190e7205..e86152327 100644 --- a/tests/python-gpu/test_gpu_updaters.py +++ b/tests/python-gpu/test_gpu_updaters.py @@ -1,15 +1,18 @@ -from typing import Dict, Any -import numpy as np import sys +from typing import Any, Dict + +import numpy as np import pytest +from hypothesis import assume, given, note, settings, strategies + import xgboost as xgb -from hypothesis import given, strategies, assume, settings, note +from xgboost import testing sys.path.append("tests/python") -import testing as tm import test_updaters as test_up +import testing as tm -pytestmark = pytest.mark.timeout(30) +pytestmark = testing.timeout(30) parameter_strategy = strategies.fixed_dictionaries({ 'max_depth': strategies.integers(0, 11), diff --git a/tests/python/test_data_iterator.py b/tests/python/test_data_iterator.py index 71e0e2f26..0416bd8a4 100644 --- a/tests/python/test_data_iterator.py +++ b/tests/python/test_data_iterator.py @@ -1,12 +1,15 @@ -import xgboost as xgb -from xgboost.data import SingleBatchInternalIter as SingleBatch import numpy as np -from testing import IteratorForTest, non_increasing, make_batches import pytest -from hypothesis import given, strategies, settings +from hypothesis import given, settings, strategies from scipy.sparse import csr_matrix +from testing import IteratorForTest, make_batches, non_increasing +from xgboost.data import SingleBatchInternalIter as SingleBatch + +import xgboost as xgb +from xgboost import testing + +pytestmark = testing.timeout(30) -pytestmark = pytest.mark.timeout(30) def test_single_batch(tree_method: str = "approx") -> None: from sklearn.datasets import load_breast_cancer diff --git a/tests/python/test_demos.py b/tests/python/test_demos.py index 6dc678446..63e44c0b0 100644 --- a/tests/python/test_demos.py +++ b/tests/python/test_demos.py @@ -1,10 +1,13 @@ import os import subprocess -import pytest -import testing as tm import sys -pytestmark = pytest.mark.timeout(30) +import pytest +import testing as tm + +from xgboost import testing + +pytestmark = testing.timeout(30) ROOT_DIR = tm.PROJECT_ROOT DEMO_DIR = os.path.join(ROOT_DIR, 'demo') diff --git a/tests/python/test_linear.py b/tests/python/test_linear.py index e1e7fbdf9..78e604635 100644 --- a/tests/python/test_linear.py +++ b/tests/python/test_linear.py @@ -1,9 +1,11 @@ import testing as tm -import pytest -from hypothesis import strategies, given, settings, note -import xgboost as xgb +from hypothesis import given, note, settings, strategies + +import xgboost as xgb +from xgboost import testing + +pytestmark = testing.timeout(10) -pytestmark = pytest.mark.timeout(10) parameter_strategy = strategies.fixed_dictionaries({ 'booster': strategies.just('gblinear'), diff --git a/tests/python/test_openmp.py b/tests/python/test_openmp.py index 847c0c9e2..950d15d86 100644 --- a/tests/python/test_openmp.py +++ b/tests/python/test_openmp.py @@ -1,14 +1,16 @@ import os -import tempfile import subprocess +import tempfile -import xgboost as xgb import numpy as np import pytest - import testing as tm -pytestmark = pytest.mark.timeout(10) +import xgboost as xgb +from xgboost import testing + +pytestmark = testing.timeout(10) + class TestOMP: def test_omp(self): diff --git a/tests/python/test_spark/test_spark_local.py b/tests/python/test_spark/test_spark_local.py index a7dff652b..b7505b4a8 100644 --- a/tests/python/test_spark/test_spark_local.py +++ b/tests/python/test_spark/test_spark_local.py @@ -9,6 +9,7 @@ import pytest import testing as tm import xgboost as xgb +from xgboost import testing if tm.no_spark()["condition"]: pytest.skip(msg=tm.no_spark()["reason"], allow_module_level=True) @@ -37,7 +38,7 @@ from .utils import SparkTestCase logging.getLogger("py4j").setLevel(logging.INFO) -pytestmark = pytest.mark.timeout(60) +pytestmark = testing.timeout(60) class XgboostLocalTest(SparkTestCase): diff --git a/tests/python/test_with_dask.py b/tests/python/test_with_dask.py index 3b8df9996..c06232e99 100644 --- a/tests/python/test_with_dask.py +++ b/tests/python/test_with_dask.py @@ -29,6 +29,7 @@ from test_with_sklearn import run_data_initialization, run_feature_weights from xgboost.data import _is_cudf_df import xgboost as xgb +from xgboost import testing if sys.platform.startswith("win"): pytest.skip("Skipping dask tests on Windows", allow_module_level=True) @@ -44,7 +45,7 @@ from xgboost.dask import DaskDMatrix dask.config.set({"distributed.scheduler.allowed-failures": False}) -pytestmark = pytest.mark.timeout(30) +pytestmark = testing.timeout(30) if hasattr(HealthCheck, 'function_scoped_fixture'): suppress = [HealthCheck.function_scoped_fixture] diff --git a/tests/python/test_with_sklearn.py b/tests/python/test_with_sklearn.py index 62c51f5b7..a5f5ddb6f 100644 --- a/tests/python/test_with_sklearn.py +++ b/tests/python/test_with_sklearn.py @@ -1,20 +1,20 @@ -from typing import Callable, Optional import collections import importlib.util -import numpy as np -import xgboost as xgb -import testing as tm -import tempfile -import os -import shutil -import pytest import json +import os +import tempfile +from typing import Callable, Optional + +import numpy as np +import pytest +import testing as tm +from sklearn.utils.estimator_checks import parametrize_with_checks + +import xgboost as xgb +from xgboost import testing rng = np.random.RandomState(1994) - -pytestmark = [pytest.mark.skipif(**tm.no_sklearn()), pytest.mark.timeout(30)] - -from sklearn.utils.estimator_checks import parametrize_with_checks +pytestmark = [pytest.mark.skipif(**tm.no_sklearn()), testing.timeout(30)] def test_binary_classification():