My minimum example is
#!/usr/bin/python3
import warnings
warnings.warn(\'Run Forest run!\', stacklevel=2)
warnings.warn(\'Run Forest run!\')
Turns out it is possible to let warnings.warn()
collect all the info and just costumize the way the info is printed:
#!/usr/bin/python3
import warnings
def warning_on_one_line(message, category, filename, lineno, file=None, line=None):
return '%s:%s: %s: %s\n' % (filename, lineno, category.__name__, message)
warnings.formatwarning = warning_on_one_line
warnings.warn('Run Forest run!', stacklevel=2)
warnings.warn('Run Forest run!')
Output:
sys:1: UserWarning: Run Forest run!
./file.py:15: UserWarning: Run Forest run!
Source: Python module of the week