Issue
How does one use DeprecationWarning
and PendingDeprecationWarning
to inform developers/tests (but not end users) of an upcoming deprecation along with the python foo.py -W
controls?
The following snippet is an isolated repro of what doesn't work as I expect it to, but also I can't figure out how to make -W
work at all.
test_deprecation.py
from warnings import warn
def warningfunction():
warn("this is deprecated", DeprecationWarning, 2)
def pendingfunction():
warn("pending", PendingDeprecationWarning, 2)
def test_warning():
warningfunction()
def test_pending():
pendingfunction()
if __name__ == '__main__':
warningfunction()
pendingfunction()
Running as pytest test_deprecation.py -vv
, both warnings come as expected. This is good at least!
Running as python test_deprecation.py
, get only the first warning (because it's in main). This is what I would expect as well!
Running as python test_deprecation.py -Wa
, still only get the first warning. This is the part I don't expect. Isn't -Wa
supposed to turn on all warnings?
Running as python test_deprecation.py -Wi
(ignore warnings), still only get the first warning. Also not expected. Isn't -Wi
supposed to ignore all warnings?
-Wdefault # Warn once per call location
-Werror # Convert to exceptions
-Walways # Warn every time
-Wmodule # Warn once per calling module
-Wonce # Warn once per Python process
-Wignore # Never warn
The action names can be abbreviated as desired (e.g. -Wi, -Wd, -Wa, -We) and the interpreter will resolve them to the appropriate action name.
from https://docs.python.org/3/using/cmdline.html#cmdoption-w
(python3.8 btw)
echo $PYTHONWARNINGS
is empty
Solution
You're passing -Wa
and -Wi
as arguments to the script. You need to put them before the script name to treat them as options for the interpreter itself.
Answered By - user2357112 Answer Checked By - Gilberto Lyons (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.