Skip to content

Commit

Permalink
Disable pytest-timeout for now. (#8348)
Browse files Browse the repository at this point in the history
  • Loading branch information
trivialfis authored Oct 17, 2022
1 parent fcddbc9 commit 2176e51
Show file tree
Hide file tree
Showing 13 changed files with 102 additions and 53 deletions.
25 changes: 24 additions & 1 deletion python-package/xgboost/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand Down Expand Up @@ -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)
9 changes: 6 additions & 3 deletions tests/python-gpu/test_gpu_linear.py
Original file line number Diff line number Diff line change
@@ -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'),
Expand Down
12 changes: 7 additions & 5 deletions tests/python-gpu/test_gpu_pickling.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
'''Test model IO with pickle.'''
import json
import os
import pickle
import numpy as np
import subprocess
import os
import sys
import json

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
Expand Down
12 changes: 7 additions & 5 deletions tests/python-gpu/test_gpu_prediction.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -16,8 +17,8 @@ def noop(*args, **kwargs):

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)

Expand All @@ -32,7 +33,8 @@ def noop(*args, **kwargs):
'num_parallel_tree': strategies.sampled_from([1, 4]),
})

pytestmark = pytest.mark.timeout(20)
pytestmark = testing.timeout(20)


class TestGPUPredict:
def test_predict(self):
Expand Down
18 changes: 11 additions & 7 deletions tests/python-gpu/test_gpu_ranking.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
13 changes: 8 additions & 5 deletions tests/python-gpu/test_gpu_updaters.py
Original file line number Diff line number Diff line change
@@ -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),
Expand Down
13 changes: 8 additions & 5 deletions tests/python/test_data_iterator.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 5 additions & 2 deletions tests/python/test_demos.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import os
import subprocess
import sys

import pytest
import testing as tm
import sys

pytestmark = pytest.mark.timeout(30)
from xgboost import testing

pytestmark = testing.timeout(30)

ROOT_DIR = tm.PROJECT_ROOT
DEMO_DIR = os.path.join(ROOT_DIR, 'demo')
Expand Down
8 changes: 5 additions & 3 deletions tests/python/test_linear.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import testing as tm
import pytest
from hypothesis import strategies, given, settings, note
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'),
Expand Down
10 changes: 6 additions & 4 deletions tests/python/test_openmp.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
3 changes: 2 additions & 1 deletion tests/python/test_spark/test_spark_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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)
Expand Down Expand Up @@ -37,7 +38,7 @@

logging.getLogger("py4j").setLevel(logging.INFO)

pytestmark = pytest.mark.timeout(60)
pytestmark = testing.timeout(60)


class XgboostLocalTest(SparkTestCase):
Expand Down
3 changes: 2 additions & 1 deletion tests/python/test_with_dask.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
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)
Expand All @@ -44,7 +45,7 @@

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]
Expand Down
22 changes: 11 additions & 11 deletions tests/python/test_with_sklearn.py
Original file line number Diff line number Diff line change
@@ -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

rng = np.random.RandomState(1994)
import numpy as np
import pytest
import testing as tm
from sklearn.utils.estimator_checks import parametrize_with_checks

pytestmark = [pytest.mark.skipif(**tm.no_sklearn()), pytest.mark.timeout(30)]
import xgboost as xgb
from xgboost import testing

from sklearn.utils.estimator_checks import parametrize_with_checks
rng = np.random.RandomState(1994)
pytestmark = [pytest.mark.skipif(**tm.no_sklearn()), testing.timeout(30)]


def test_binary_classification():
Expand Down

0 comments on commit 2176e51

Please sign in to comment.