[TIP] Test discovery for unittest

holger krekel holger at merlinux.eu
Sun Apr 5 09:06:44 PDT 2009


On Sun, Apr 05, 2009 at 14:38 +0300, Marius Gedminas wrote:
> On Sat, Apr 04, 2009 at 09:18:36AM +0200, holger krekel wrote:
> > Huh?  There is nothing in nose or py.test that prevents your from 
> > doing all the compilcated inheritance trees you'd like to do. 
> > Both can also run unittest.py style files.  
> 
> That turned out not to be the case in my experience.  I was working on
> Pylons-based project where the team wanted to use py.test instead of
> nose.  We had to make changes to the test suite (specifically, make the
> classes inherit object instead of unittest.TestCase) to get them to
> work with py.test (and move four lines of code from the Pylons Nose
> plugin into the base test class, which is not py.tests's fault ;).
> 
> It could be related to the decision to use py.test 1.0.0 alpha (some svn
> snapshot).
> 
> And, also (IIRC) rename the setUp methods to setup_method and change the
> signature to accept one extra argument.  I don't know if that was
> necessary, or just something done to match the style of the other test
> suites in the existing parts of the (non-Pylons) codebase.

did you try using the pytest_unittest.py plugin?  You can enable
it with "-p unittest" or by putting a "pytest_plugins = 'unittest'" 
into a conftest.py file.  This allows to collect and run
unittest.py-style tests (including setUp/tearDown).  
You can mix with py.test-style style tests in the same file. 

Anyway, my comment was more aimed at the fact that a
TestClass can just use normal python inheritance for
implementing layered setups or having a set of base tests.  
It's true that if you subclass from a base class which 
needs parameters for instantiating it, you will need 
a plugin or some custom code to provide these parameters. 
The 50-line "py/test/plugin/pytest_unittest.py" plugin 
is an example for that.  

cheers,
holger

-- 
Metaprogramming, Python, Testing: http://tetamap.wordpress.com
Python, PyPy, pytest contracting: http://merlinux.eu 



More information about the testing-in-python mailing list