mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Add logging for warnings during test suite run
The default configuration for the warnings module changed some time ago so we lost the ability to detect deprecation warnings and such early. This commit sets up the test suite to redirect all warnings through our logging system. Additionally we enable DeprecationWarnings as a default and throw exceptions on all warnings related to pelican modules. This enables output of warnings related to dependencies, while letting tests only fail if the warnings are originating from pelican's source. Also adding a test to detect if warnings cause an Exception as expected.
This commit is contained in:
parent
661ee49eda
commit
e50abb20b3
3 changed files with 46 additions and 7 deletions
|
|
@ -172,21 +172,31 @@ class LimitLogger(SafeLogger):
|
|||
logging.setLoggerClass(LimitLogger)
|
||||
|
||||
|
||||
def init(level=None, handler=logging.StreamHandler()):
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
def get_formatter():
|
||||
if os.isatty(sys.stdout.fileno()) and not sys.platform.startswith('win'):
|
||||
fmt = ANSIFormatter()
|
||||
return ANSIFormatter()
|
||||
else:
|
||||
fmt = TextFormatter()
|
||||
handler.setFormatter(fmt)
|
||||
return TextFormatter()
|
||||
|
||||
|
||||
def init(level=None, handler=logging.StreamHandler(), name=None):
|
||||
|
||||
logger = logging.getLogger(name)
|
||||
|
||||
handler.setFormatter(get_formatter())
|
||||
logger.addHandler(handler)
|
||||
|
||||
if level:
|
||||
logger.setLevel(level)
|
||||
|
||||
|
||||
def log_warnings():
|
||||
import warnings
|
||||
logging.captureWarnings(True)
|
||||
warnings.simplefilter("default", DeprecationWarning)
|
||||
init(logging.DEBUG, name='py.warnings')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
init(level=logging.DEBUG)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue