samedi 2 mai 2015

Python unit test using nosetests.exe prevent logging in files using logging module

I created a class for logging:

import logging, time

class QaLogger():

def __init__(self, filename='LOG.log', logger_name='Qa_Automation'):
    logging.basicConfig(filename=filename, level=logging.INFO)
    self.logger = logging.getLogger(logger_name)
    self.logger.initialized = True

def log(self, msg):
    localtime  = time.localtime()
    time_string = time.strftime("%Y-%m-%d-%H:%M:%S", localtime)
    self.logger.info(time_string + ": " + msg)

Then I use this to log output to files when I run my tests: Example:

    self.logger = QaLogger('qa_req_response.log', 'QA')
    self.logger.log('QA_LOGGING ')

This works fine when I run my tests using PyCharm IDE; The logging in files is done.

My issue is that it does not work when I run the unittests using nosetests.exe from command line like:

C:\Python27\Scripts\nosetests.exe .\TestFunction.py --with-xunit

with or without --with-xunit

Logging is not done and log files remain empty.

How can I solve this issue? Thanks

Aucun commentaire:

Enregistrer un commentaire