Skip to content
Advertisement

How to use pytest fixture with fixture factory?

In scikit-learn, there is a function parametrize_with_checks() that is used as a pytest fixture factory–it returns a pytest.mark.parametrize fixture, and is called as a decorator with an iterable of estimators, e.g.

JavaScript

My issue is that my list of estimators may change (or I may have multiple lists), and each list I am setting up in a fixture.

Here is a M(N)WE:

JavaScript

However, models is still a function object when it is passed to parametrize_with_checks, so it throws an error. How can I get around this?

Advertisement

Answer

parametrize_with_checks() can not work with the values set by fixtures. It handles models just as a function, not a fixture. You can access fixtures only from test functions.
So, looks like you need to set the models as a list or make a call to the model function in parametrize_with_checks()

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement