0

Situation is as follows :

I am redoing all the test suites for my work and there is a LOT of warnings but not all of them I can fix.
More specifically, the project has dependencies that I cannot interfer with and cannot fix them

Here is an exemple :

/venv/lib/python3.9/site-packages/flask_restx/api.py:275: DeprecationWarning: 'ERROR_404_HELP' config setting is deprecated and will be removed in the future. Use 'RESTX_ERROR_404_HELP' instead.

In this case the warning originates from the venv directory and I cannot do anything about it for now

How can I just have all the other warnings without having to scroll through hundreds of warnings to find them ?
I would like to ignore all warnings that have venv/ in their path

  • 1
    Could [this](https://stackoverflow.com/a/53706908/17200348) answer help? – B Remmelzwaal Mar 06 '23 at 16:23
  • unless I am not understanding the way it works ( which is very possible ) I would have to add an ignore rule for all the different warnings which would be a lot. – Matthieu Raynaud de Fitte Mar 06 '23 at 16:31
  • It would be worth a shot using [`pip freeze -l`](https://pip.pypa.io/en/latest/cli/pip_freeze/#cmdoption-l) and generating the warning suppressions from the output of that. – B Remmelzwaal Mar 06 '23 at 16:34

1 Answers1

0

Don't think of this as suppressing warnings from a specific directory, but from a module. As the warning is generated by the warnings module, you can also use warnings to suppress it. Add the following to the test module that triggers the warning:

import warnings

warnings.filterwarnings("ignore", DeprecationWarning, 'flask_restx\.api', 275)

This is very precise: it will disable DeprecationWarnings produced by line 275 of any module whose full name starts with flask_restx.api. If this pops up on multiple lines, you can remove 275 and let the default of covering any line in the matched module(s) be used.

flask_restx\.api is a regular expression; you can modify that to match multiple modules from which the warning might be raised. You can also simply define multiple filters to cover multiple modules if the regular expression would get too confusing.

chepner
  • 497,756
  • 71
  • 530
  • 681
  • I'm a bit confused, I am getting a ``AttributeError: module 'warnings' has no attribute 'DeprecationWarning'`` although I am using Python 3.9.4 and I can see it in the documentation – Matthieu Raynaud de Fitte Mar 06 '23 at 16:41
  • My bad; none of those exceptions are attributes of the `warnings` module; they are in the built-in namespace. – chepner Mar 06 '23 at 16:43