estimator_checks_generator#

sklearn.utils.estimator_checks.estimator_checks_generator(estimator, *, legacy: bool = True, expected_failed_checks: dict[str, str] | None = None, mark: Literal['xfail', 'skip', None] | None = None, xfail_strict: bool | None = None)[source]#

Iteratively yield all check callables for an estimator.

This function is used by parametrize_with_checks and check_estimator to yield all check callables for an estimator. In most cases, these functions should be used instead. When implementing a custom equivalent, please refer to their source code to understand how estimator_checks_generator is intended to be used.

Added in version 1.6.

Parameters:
estimatorestimator object

Estimator instance for which to generate checks.

legacybool, default=True

Whether to include legacy checks. Over time we remove checks from this category and move them into their specific category.

expected_failed_checksdict[str, str], default=None

Dictionary of the form {check_name: reason} for checks that are expected to fail.

mark{“xfail”, “skip”} or None, default=None

Whether to mark the checks that are expected to fail as xfail(pytest.mark.xfail) or skip. Marking a test as “skip” is done via wrapping the check in a function that raises a SkipTest exception.

xfail_strictbool, default=None

Whether to run checks in xfail strict mode. This option is ignored unless mark="xfail". If True, checks that are expected to fail but actually pass will lead to a test failure. If False, unexpectedly passing tests will be marked as xpass. If None, the default pytest behavior is used.

Added in version 1.8.

Returns:
estimator_checks_generatorgenerator

Generator that yields (estimator, check) tuples.