我创建了一个用于日志记录的类:
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)
我使用这个工具来将测试输出记录到文件中: 示例:
self.logger = QaLogger('qa_req_response.log', 'QA')
self.logger.log('QA_LOGGING ')
当我在PyCharm IDE中运行测试时,这个功能可以正常工作;日志记录已经完成。
我的问题在于,当我通过命令行运行nosetests.exe来运行单元测试时,它无法正常工作,如下所示:
> C:\Python27\Scripts\nosetests.exe .\TestFunction.py --with-xunit
使用或不使用--with-xunit
未执行日志记录,日志文件为空。
如何解决此问题?