3

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?

0

1 Answer 1

3

Try the --nologcapture option on the command line. Nose's logcapture plugin intercepts all logging by default if I recall correctly, which results in basicConfig not having the expected effect.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.