Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #27844 > unrolled thread

Publish unittest results from test discovery

Started byLucretiel <lucretiel@gmail.com>
First post2012-08-24 17:25 -0700
Last post2012-08-25 17:55 +0200
Articles 4 — 4 participants

Back to article view | Back to comp.lang.python


Contents

  Publish unittest results from test discovery Lucretiel <lucretiel@gmail.com> - 2012-08-24 17:25 -0700
    Re: Publish unittest results from test discovery Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-08-25 01:03 +0000
      Re: Publish unittest results from test discovery Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-08-25 08:57 +0100
    Re: Publish unittest results from test discovery Peter Otten <__peter__@web.de> - 2012-08-25 17:55 +0200

#27844 — Publish unittest results from test discovery

FromLucretiel <lucretiel@gmail.com>
Date2012-08-24 17:25 -0700
SubjectPublish unittest results from test discovery
Message-ID<afce5fc2-854e-4c69-95ba-248bc5a34fd8@googlegroups.com>
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?

[toc] | [next] | [standalone]


#27845

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2012-08-25 01:03 +0000
Message-ID<50382477$0$6574$c3e8da3$5496439d@news.astraweb.com>
In reply to#27844
On Fri, 24 Aug 2012 17:25:05 -0700, Lucretiel wrote:

[...]
> Is there a way to get unittest disover to work with xmlrunner

Steady on there! It's only been about an hour and a half since you last 
asked this exact same question, almost word-for-word identical. The more 
specialised the question, the longer it may take for somebody who knows 
the answer to reply. For something like this, I would wait at least a 
couple of days before replying to your original post. (Don't just re-post 
the question in a new thread, keep the response in a single thread.)

I have no idea about xmlrunner and unittest discovery, sorry.


-- 
Steven

[toc] | [prev] | [next] | [standalone]


#27856

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2012-08-25 08:57 +0100
Message-ID<mailman.3789.1345881324.4697.python-list@python.org>
In reply to#27845
On 25/08/2012 02:03, Steven D'Aprano wrote:
> On Fri, 24 Aug 2012 17:25:05 -0700, Lucretiel wrote:
>
> [...]
>> Is there a way to get unittest disover to work with xmlrunner
>
> Steady on there! It's only been about an hour and a half since you last
> asked this exact same question, almost word-for-word identical. The more
> specialised the question, the longer it may take for somebody who knows
> the answer to reply. For something like this, I would wait at least a
> couple of days before replying to your original post. (Don't just re-post
> the question in a new thread, keep the response in a single thread.)
>
> I have no idea about xmlrunner and unittest discovery, sorry.
>
>

I entirely agree with Steven's comments.  I'd put a question like this 
on a specialised list.  How about gmane.comp.python.testing.general ? 
Sorry I've no idea what it's called elsewhere.

-- 
Cheers.

Mark Lawrence.

[toc] | [prev] | [next] | [standalone]


#27877

FromPeter Otten <__peter__@web.de>
Date2012-08-25 17:55 +0200
Message-ID<mailman.3806.1345910102.4697.python-list@python.org>
In reply to#27844
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
$ 

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web