Skip to content
Advertisement

Pytest: How to locate a FutureWarning and fix it?

In my current project when I run my tests (with pytest) I get this output (besides others):

JavaScript

This FutureWarning is quite clear – from version 1.0 (I’m using 0.24 at the moment) there will be change to some parameters and I will not be able to pass standardize as positional arguments.

But the question is – How can I locate where should I change this positional argument to a keyword one?

I could go to validation.py that is mentioned in the warning output, but there is general _deprecate_positional_args function which does not tell me which code call it.

In this particular case I’m guessing this will come from PowerTransformer imported from sklearn.preprocessing which is used in my code, has standardize parameter and is tested in the listed tests. Is there a general way how to find the cause of that easily for any FutureWarning? Or do I need to check all my codes and try to find it somehow?

Advertisement

Answer

Pytest let you raise a FutureWarning as an error, this way it points to the code location where the warning was raised, the simplest way is through the warning flag

JavaScript

or inside test_script.py through pytestmark

JavaScript

you can read more about specifying the action being taken on a Warning here and here.

Example

Considering the following dummy example test_transform.py script

JavaScript

and running on terminal

JavaScript

the logs show me exactly that PowerTransformer raised the FutureWarning.

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