Skip to content

Instantly share code, notes, and snippets.

@UnderGrounder96
Last active November 16, 2020 09:58
Show Gist options
  • Save UnderGrounder96/61b0898fcce91954b4f0ee9b87fb18fc to your computer and use it in GitHub Desktop.
Save UnderGrounder96/61b0898fcce91954b4f0ee9b87fb18fc to your computer and use it in GitHub Desktop.
Basic logging pytest
[pytest]
log_level = ERROR ; sets both log_cli_level and log_file_level
log_cli = True
log_cli_format = %(message)s
log_file = reports/report.log
log_file_date_format= %d/%b/%Y %H:%M:%S
log_file_level = CRITICAL ; or one can set it via log_level for values above WARNING
log_file_format = %(asctime)s (%(filename)s:%(lineno)s) [%(levelname)8s]: %(message)s
#!/usr/bin/env python3
# pip install -U pytest
import logging
logger = logging.getLogger(__name__)
class TestLoggingPytest:
def test_logging_pytest(self):
logger.debug('debug')
logger.info('info')
logger.warning('warning')
logger.error('error')
logger.critical('critical')
assert True
# output
# tests/test_logging_pytest.py::TestLoggingPytest::test_logging_pytest
# --------------live log call --------------------
# error
# critical
# reports/report.log
# 12/Sep/2020 16:09:37 (test_logging_pytest.py:14) [CRITICAL]: critical
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment