bobber6467 / python-nose

Automatically exported from code.google.com/p/python-nose
0 stars 0 forks source link

attrib plugin runs setup_module/teardown_module even when no tests match the expression #419

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I have this test structure:

tests/
 __init__.py
 test_foo.py

__init__.py:
------------
import logging
LOG = logging.getLogger(__name__)

def setup_module():
    LOG.info('Opening tests2')

def teardown_module():
    LOG.info('Closing tests2')

test_foo.py:
------------
from nose.plugins.attrib import attr
from unittest import TestCase
import logging
LOG = logging.getLogger(__name__)

class TestClass(TestCase):

    @attr(tags=(1,2))
    def test_1(self):
        LOG.info('in %s', self.id())

When I call:
$ nosetests -sv -a tags=3 tests/
15:35:21 -     INFO [MainThread]: Opening tests2
15:35:21 -     INFO [MainThread]: Closing tests2

----------------------------------------------------------------------
Ran 0 tests in 0.003s

OK

No tests have tags==3 (obviously), but the setup_module/teardown_module were 
still executed.

I expect the context setup/teardown to be executed when *at least* one of the 
tests matches attrib module's expression.

Original issue reported on code.google.com by jonsibo...@gmail.com on 12 May 2011 at 10:40

GoogleCodeExporter commented 8 years ago
Yeah, I see what you mean.  I believe this is fixable.

Original comment by kumar.mcmillan on 13 May 2011 at 3:35

GoogleCodeExporter commented 8 years ago
Do you have any hints on where to start? I'd like to patch it myself, as this 
is a pretty important missing feature for us.

Original comment by jonsibo...@gmail.com on 13 May 2011 at 5:11

GoogleCodeExporter commented 8 years ago
Clone the code from here using a Mercurial client 
http://code.google.com/p/python-nose/source/checkout  When you have the code, 
open DEVELOPERS.txt and that will guide you through the basics of setting up 
your environment and guidelines for patches.

As for this feature, you may have to wrap all module contexts in a lazy loader 
the same way classes are.  This will be kind of a hairy feature to get right 
but go for it!

Original comment by kumar.mcmillan on 13 May 2011 at 9:28