check_estimator#

check_estimator(estimator, raise_exceptions=False, tests_to_run=None, fixtures_to_run=None, verbose=True, tests_to_exclude=None, fixtures_to_exclude=None)[source]#

对单个估计器运行所有测试。

对估计器运行的测试

test_all_estimators 中的所有测试,以及估计器 scitype 模块中的所有接口兼容性测试

例如,如果估计器是预测器,则运行 test_all_forecasters

参数:
estimator估计器类或估计器实例
raise_exceptionsbool 类型, 可选, 默认值=False

是否在结果字典中返回异常/失败,或者抛出它们

  • 如果为 False: 在返回的 results 字典中返回异常

  • 如果为 True: 在发生异常时抛出异常

tests_to_runstr 或 str 列表, 可选. 默认值 = 运行所有测试.

要运行的测试名称 (测试/函数名字符串)。将运行的测试子集限制为此处给定的测试。

fixtures_to_runstr 或 str 列表, 可选. 默认值 = 运行所有测试.

pytest 测试-fixture 组合代码,指定要运行哪些测试-fixture 组合。将要运行的测试和 fixture 子集限制为此处给定的列表。如果同时提供了 tests_to_run 和 fixtures_to_run,则运行它们的 并集,即 tests_to_run 中所有测试的所有测试-fixture 组合,

以及 fixtures_to_run 中的所有测试-fixture 组合。

verbosestr 类型, 可选, 默认值=True.

是否打印出运行测试的详细摘要。

tests_to_excludestr 或 str 列表, 要排除的测试名称. 默认值 = None

在通过 tests_to_run 进行子集划分后,移除不应运行的测试。

fixtures_to_excludestr 或 str 列表, 要排除的 fixtures. 默认值 = None

移除不应运行的测试-fixture 组合。这在通过 fixtures_to_run 进行子集划分后完成。

返回:
resultsdict, 自身测试的结果字典

键是 test/fixture 字符串,与 pytest 中相同,例如 test[fixture] 条目是字符串 “PASSED” 如果测试通过,或者是测试未通过时抛出的异常 仅当所有测试通过或 raise_exceptions=False 时返回

抛出:
如果 raise_exceptions=True,
直接抛出测试产生的任何异常

示例

>>> from sktime.transformations.series.exponent import ExponentTransformer
>>> from sktime.utils.estimator_checks import check_estimator

为 ExponentTransformer 类运行所有测试,这将使用来自 get_test_params 的所有实例和兼容场景

>>> results = check_estimator(ExponentTransformer)
All tests PASSED!

为特定的 ExponentTransformer 运行所有测试,这将使用传递的实例和兼容场景

>>> results = check_estimator(ExponentTransformer(42))
All tests PASSED!

为 ExponentTransformer 运行特定测试 (所有 fixtures)

>>> results = check_estimator(ExponentTransformer, tests_to_run="test_clone")
All tests PASSED!

{‘test_clone[ExponentTransformer-0]’: ‘PASSED’, ‘test_clone[ExponentTransformer-1]’: ‘PASSED’}

为 ExponentTransformer 运行一个特定的测试-fixture-组合

>>> check_estimator(
...    ExponentTransformer, fixtures_to_run="test_clone[ExponentTransformer-1]"
... )
All tests PASSED!
{'test_clone[ExponentTransformer-1]': 'PASSED'}