Turn warning messages into Python warnings. (#9387)
This commit is contained in:
@@ -3,6 +3,7 @@ import os
|
||||
import pickle
|
||||
import random
|
||||
import tempfile
|
||||
import warnings
|
||||
from typing import Callable, Optional
|
||||
|
||||
import numpy as np
|
||||
@@ -1091,25 +1092,22 @@ def test_constraint_parameters():
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.filterwarnings("error")
|
||||
def test_parameter_validation():
|
||||
reg = xgb.XGBRegressor(foo='bar', verbosity=1)
|
||||
reg = xgb.XGBRegressor(foo="bar", verbosity=1)
|
||||
X = np.random.randn(10, 10)
|
||||
y = np.random.randn(10)
|
||||
with tm.captured_output() as (out, err):
|
||||
with pytest.warns(Warning, match="foo"):
|
||||
reg.fit(X, y)
|
||||
output = out.getvalue().strip()
|
||||
|
||||
assert output.find('foo') != -1
|
||||
|
||||
reg = xgb.XGBRegressor(n_estimators=2, missing=3,
|
||||
importance_type='gain', verbosity=1)
|
||||
reg = xgb.XGBRegressor(
|
||||
n_estimators=2, missing=3, importance_type="gain", verbosity=1
|
||||
)
|
||||
X = np.random.randn(10, 10)
|
||||
y = np.random.randn(10)
|
||||
with tm.captured_output() as (out, err):
|
||||
reg.fit(X, y)
|
||||
output = out.getvalue().strip()
|
||||
|
||||
assert len(output) == 0
|
||||
with warnings.catch_warnings():
|
||||
reg.fit(X, y)
|
||||
|
||||
|
||||
def test_deprecate_position_arg():
|
||||
|
||||
Reference in New Issue
Block a user