7

Is there a way to show DeprecationWarnings if and only if they are triggered by my code (i.e, if I can actually fix them)?

For example, if the foo module is deprecated (and calls warnings.warn on import), I would like to see the warning if the import call is in one of "my" files (identified by e.g. its path), but I'd like it to be hidden if my code imports bar (also outside of my control), which then imports foo.

The warnings.filterwarnings function takes a module parameter, but as far as I can tell this is matched against the module that generated the warning. I believe what I'm interested in is the module that is one stack frame higher.

Nikratio
  • 2,338
  • 2
  • 29
  • 43

0 Answers0