#!/usr/bin/env python3 -u
# coding: utf-8

__author__ = ["mloning"]
__all__ = []

from companion_package.registry import get_estimators


def configure_pytest_generate_tests(estimator_types=None):

    def pytest_generate_tests(metafunc):
        """Test parameterization routine for pytest.

        Fixtures parameterized
        ----------------------
        estimator_class: estimator inheriting from BaseObject
            ranges over all estimator classes not excluded by EXCLUDED_TESTS
        estimator_instance: instance of estimator inheriting from BaseObject
            ranges over all estimator classes not excluded by EXCLUDED_TESTS
            instances are generated by create_test_instance class method
        """
        estimator_classes = get_estimators(
            estimator_types=estimator_types, return_names=False)

        if "estimator_class" in metafunc.fixturenames:
            metafunc.parametrize("estimator_class", estimator_classes)

        # if estimator test, construct all instances for the test
        if "estimator_instance" in metafunc.fixturenames:
            estimator_instances = [estimator.create_test_instance()
                                   for estimator in estimator_classes]
            metafunc.parametrize("estimator_instance", estimator_instances)

    return pytest_generate_tests
