Python : Pytest logger
Create file : /project/pytest.ini
[pytest]testpaths = tests/python_paths = ./console_output_style = progressaddopts = -rsxX -qlog_cli = 1log_cli_level = INFOlog_cli_format = %(asctime)s [%(levelname)8s] %(message)s (%(filename)s:%(lineno)s)log_cli_date_format=%Y-%m-%d %H:%M:%Slog_file_date_format = %Y-%m-%d %H:%M:%Slog_file_format = %(asctime)s %(levelname)s %(message)slog_date_format = %Y-%m-%d %H:%M:%Slog_file=simple_logger.loglog_print = Truepython_files =test_*.py*_test.py
Using without class :
LOGGER = logging.getLogger(__name__) #Decalared as a global
LOGGER.error("Unable to make connection to DB")#to log fails inside/ouside def
Usage in a class :
self.LOGGER = logging.getLogger(__name__)#inside a constructor
self.LOGGER.error("Unable to make connection to DB")#to log fails
No comments:
Post a Comment