Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!border1.nntp.ams2.giganews.com!border2.nntp.ams2.giganews.com!border4.nntp.ams.giganews.com!border2.nntp.ams.giganews.com!nntp.giganews.com!multikabel.net!newsfeed20.multikabel.net!news2.euro.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '(python': 0.05; 'xml,': 0.05; '__name__': 0.07; 'executed': 0.07; 'subject:test': 0.07; 'unittest': 0.07; 'python': 0.09; 'differing': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'skip:= 70': 0.10; 'def': 0.10; "'b',": 0.16; "['a',": 0.16; '__unittest': 0.16; 'code?': 0.16; 'googling': 0.16; 'received:80.91.229.3': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-dialin.net': 0.16; 'scripts.': 0.16; 'subject:unittest': 0.16; 'testprogram,': 0.16; 'unittest,': 0.16; 'wrote:': 0.17; 'basically': 0.17; 'copied': 0.17; 'element': 0.17; 'specify': 0.17; 'tests': 0.18; 'code,': 0.18; 'import': 0.21; 'discovery': 0.22; 'example': 0.23; "i've": 0.23; 'pass': 0.25; 'header:User-Agent:1': 0.26; '(most': 0.27; 'skip:# 10': 0.27; 'skip:" 50': 0.27; 'header:X-Complaints-To:1': 0.28; 'cat': 0.29; 'though.': 0.29; 'class': 0.29; 'distribute': 0.30; 'lists': 0.31; 'code': 0.31; 'file': 0.32; 'running': 0.32; 'could': 0.32; 'traceback': 0.33; 'to:addr:python-list': 0.33; 'fail': 0.35; 'there': 0.35; 'add': 0.36; 'received:org': 0.36; 'skip:u 20': 0.36; 'but': 0.36; 'wanted': 0.36; 'test': 0.36; 'xml': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'where': 0.40; 'header:Received:5': 0.40; 'your': 0.60; 'skip:u 10': 0.60; 'first': 0.61; 'solve': 0.62; 'love': 0.63; 'results': 0.65; 'discover': 0.72; 'around,': 0.84; 'subject:results': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: Publish unittest results from test discovery Date: Sat, 25 Aug 2012 17:55:05 +0200 Organization: None References: Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p5084a85d.dip.t-dialin.net User-Agent: KNode/4.7.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 71 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1345910102 news.xs4all.nl 6952 [2001:888:2000:d::a6]:38576 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:27877 Lucretiel wrote: > So I've started using unittest, and I love it. I use testdiscovery (python > -m unittest discover) so that I can distribute my tests and don't have to > manage them all manually. I wanted to start publishing my test results to > xml, though. I found xmlrunner by googling around, but it requires me to > add an if __name__ == '__main__' block to my code, which isn't executed by > unittest discover. Is there a way to get unittest disover to work with > xmlrunner, or to some other way to solve this without restructuring all my > test code? I don't see where you could specify a test runner on the commandline, but you can reuse the discovery code in your own scripts. For the following example I basically copied unittest.__main__.py: $ cat discover.py #!/usr/bin/env python import xmlrunner __unittest = True from unittest.main import main, TestProgram, USAGE_AS_MAIN TestProgram.USAGE = USAGE_AS_MAIN main(module=None, testRunner=xmlrunner.XMLTestRunner(output='test-reports')) $ cat test_alpha.py import unittest class T(unittest.TestCase): def test_alpha(self): pass def test_beta(self): self.assertEquals(["a", "b", "c"], ["a", "B", "c"]) $ ./discover.py discover Running tests... ---------------------------------------------------------------------- .F ====================================================================== FAIL [0.001s]: test_beta (test_alpha.T) ---------------------------------------------------------------------- Traceback (most recent call last): File "/somewhere/over/the/rainbow/discover/test_alpha.py", line 7, in test_beta self.assertEquals(["a", "b", "c"], ["a", "B", "c"]) AssertionError: Lists differ: ['a', 'b', 'c'] != ['a', 'B', 'c'] First differing element 1: b B - ['a', 'b', 'c'] ? ^ + ['a', 'B', 'c'] ? ^ ---------------------------------------------------------------------- Ran 2 tests in 0.002s FAILED (failures=1) Generating XML reports... $ ls discover.py test_alpha.py test_alpha.pyc test-reports $ ls test-reports/ TEST-test_alpha.T.xml $