Use pytest conventions consistently (#6337)
* Do not derive from unittest.TestCase (not needed for pytest) * assertRaises -> pytest.raises * Simplify test_empty_dmatrix with test parametrization * setUpClass -> setup_class, tearDownClass -> teardown_class * Don't import unittest; import pytest * Use plain assert * Use parametrized tests in more places * Fix test_gpu_with_sklearn.py * Put back run_empty_dmatrix_reg / run_empty_dmatrix_cls * Fix test_eta_decay_gpu_hist * Add parametrized tests for monotone constraints * Fix test names * Remove test parametrization * Revise test_slice to be not flaky
This commit is contained in:
committed by
GitHub
parent
c763b50dd0
commit
9c9070aea2
@@ -2,7 +2,6 @@ import numpy as np
|
||||
from scipy.sparse import csr_matrix
|
||||
import xgboost
|
||||
import os
|
||||
import unittest
|
||||
import itertools
|
||||
import shutil
|
||||
import urllib.request
|
||||
@@ -73,10 +72,10 @@ def test_ranking_with_weighted_data():
|
||||
assert all(p <= q for p, q in zip(is_sorted, is_sorted[1:]))
|
||||
|
||||
|
||||
class TestRanking(unittest.TestCase):
|
||||
class TestRanking:
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
def setup_class(cls):
|
||||
"""
|
||||
Download and setup the test fixtures
|
||||
"""
|
||||
@@ -119,7 +118,7 @@ class TestRanking(unittest.TestCase):
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
def teardown_class(cls):
|
||||
"""
|
||||
Cleanup test artifacts from download and unpacking
|
||||
:return:
|
||||
@@ -144,8 +143,9 @@ class TestRanking(unittest.TestCase):
|
||||
cv = xgboost.cv(self.params, self.dtrain, num_boost_round=2500,
|
||||
early_stopping_rounds=10, nfold=10, as_pandas=False)
|
||||
assert isinstance(cv, dict)
|
||||
self.assertSetEqual(set(cv.keys()), {'test-ndcg-mean', 'train-ndcg-mean', 'test-ndcg-std', 'train-ndcg-std'},
|
||||
"CV results dict key mismatch")
|
||||
assert (set(cv.keys()) == {'test-ndcg-mean', 'train-ndcg-mean', 'test-ndcg-std',
|
||||
'train-ndcg-std'},
|
||||
'CV results dict key mismatch.')
|
||||
|
||||
def test_cv_no_shuffle(self):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user