Monday, July 8, 2019

Python : Pytest logger


 Python : Pytest logger


Create file : /project/pytest.ini

[pytest]

testpaths = tests/
python_paths = ./

console_output_style = progress
addopts = -rsxX -q

log_cli = 1
log_cli_level = INFO
log_cli_format = %(asctime)s [%(levelname)8s] %(message)s (%(filename)s:%(lineno)s)
log_cli_date_format=%Y-%m-%d %H:%M:%S

log_file_date_format = %Y-%m-%d %H:%M:%S
log_file_format = %(asctime)s %(levelname)s %(message)s
log_date_format = %Y-%m-%d %H:%M:%S
log_file=simple_logger.log
log_print = True

python_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