unit testing - Python unittest report passed test -


hello have test module following under "test.py":

class testbasic(unittest.testcase):     def setup(self):         # set in here  class testa(testbasic):     def test_one(self):         self.assertequal(1,1)      def test_two(self):         self.assertequal(2,1)  if __name__ == "__main__":     unittest.main() 

and works pretty good, need way print test passed, example print output console:

test_one: passed test_two: failed 

now twist, add print statement right after self.assertequal() , passed test , print it, need run test different module, let's "test_reporter.py" have this:

import test suite = unittest.testloader().loadtestsfrommodule(test) results = unittest.texttestrunner(verbosity=0).run(suite) 

at point results when build report.

so please suggestion welcome

thanks !!

like corey's comment mentioned, if set verbosity=2 unittest print result of each test run.

results = unittest.texttestrunner(verbosity=2).run(suite) 

if want little more flexibility - , might since creating suites , using test runners - recommend take @ twisted trial. extends python's unittest module , provides few more assertions , reporting features.

writing tests same (besides subclassing twisted.trial.unittest.testcase vs python's unittest) workflow won't change. can still use testloader you'll have options of many more testreporters http://twistedmatrix.com/documents/11.1.0/api/twisted.trial.reporter.html.

for example, default testreporter treereporter returns following output: enter image description here


Comments

Popular posts from this blog

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -

python - How to create a legend for 3D bar in matplotlib? -