I had one problem that I used HTMLTestRunner to integrate my test report with python. Here is the code structure:
In the module run.py, I imported third-party module HTMLTestRunner to generate test report when perform test class testClass1 and testClass2. In these two test classes, HTMLTestRunner will collect all message from print clause and output them into an html page. However, it did not do this if I used a method from other module to print the logs in the test class. printMessage() from parse.py will be used to print messages from message.log in all cases from test class.
MESSAGE = '.././main/src/tc/logs/message.log'
def printMessage():
if not os.path.exists(MESSAGE):
return None
f = codecs.open(MESSAGE, 'r', 'utf-8')
for cnt, line in enumerate(f):
print line
-- test class sample here --
import unittest
from parse import printMessage
class TestClass1(unittest.TestCase):
def testCase1(self):
print 'test case 1 starts' # line 6
< ... codes here ...>
print 'test case 1 performing' # line 20
printMessage() # line 21. Even I didn't print message here,
# use return to return all lines and print in the test class, still not working
print 'test case 1 ends' # line 22
The problem here is after I run the test cases in the console on my Mac by python run.py, I can see the message from print clause in the html report for line 6 and line 20, but cannot see messages from line 21 and line 22, no matter test cases pass or fail. Instead, it will output the message read from the log into the console for line 21 and line 22. Really not sure why this happened...
But, if I didn't use printMessage() method, just use its code in the line 21 instead, it worked well and I can see messages output into the html page. While I don't want do this, it makes code not that simplistic.
Can anyone help me out this problem? Bugs in my code or HTMLTestRunner or something else?
Aucun commentaire:
Enregistrer un commentaire