How to skip noses of a class decorated with .plugins.attrib.attr nose in a shell

a decorator class for noses can be written like this:

from nose.plugins.attrib import attr

@attr (speed = 'slow')
class MyTestCase:
    def test_long_integration (self):
        pass
    def test_end_to_end_something (self):
        pass

As per the documentation "In Python 2.6 and up, @attr can be used in a class to set attributes in all of its test methods at once"

I couldn't find a way to test the code. Performance

nosetests -a speed=slow

      

did not help. Any help would be appreciated. Thanks in advance.

+3


source to share


1 answer


You are missing the parent class unittest.TestCase for your test, i.e .:

from unittest import TestCase
from nose.plugins.attrib import attr

@attr(speed='slow')
class MyTestCase(TestCase):
    def test_long_integration(self):
        pass
    def test_end_to_end_something(self):
        pass

class MyOtherTestCase(TestCase):
    def test_super_long_integration(self):
        pass

      

Your team should select tests based on attributes, not skip them:

$ nosetests ss_test.py -a speed=slow -v
test_end_to_end_something (ss_test.MyTestCase) ... ok
test_long_integration (ss_test.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 2 tests in 0.004s

OK

      



If you want to make a selection of the appropriate test, you can use the "-A" attribute and use the full python syntax:

$ nosetests ss_test.py -A "speed=='slow'" -v
test_end_to_end_something (ss_test.MyTestCase) ... ok
test_long_integration (ss_test.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 2 tests in 0.003s

OK

      

here's how to skip slow tests:

$ nosetests ss_test.py -A "speed!='slow'" -v
test_super_long_integration (ss_test.MyOtherTestCase) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.003s

OK

      

+4


source







All Articles