Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling Python nosetests

When using nosetests for Python it is possible to disable a unit test by setting the test function's __test__ attribute to false. I have implemented this using the following decorator:

def unit_test_disabled():     def wrapper(func):          func.__test__ = False          return func      return wrapper  @unit_test_disabled def test_my_sample_test()     #code here ... 

However, this has the side effect of calling wrapper as the unit test. Wrapper will always pass but it is included in nosetests output. Is there another way of structuring the decorator so that the test will not run and does not appear in nosetests output.

like image 479
Richard Dorman Avatar asked Jul 13 '09 15:07

Richard Dorman


2 Answers

Nose already has a builtin decorator for this:

from nose.tools import nottest  @nottest def test_my_sample_test()     #code here ... 

Also check out the other goodies that nose provides: https://nose.readthedocs.org/en/latest/testing_tools.html

like image 90
Christian Oudard Avatar answered Oct 05 '22 07:10

Christian Oudard


You can also use unittest.skip decorator:

import unittest   @unittest.skip("temporarily disabled") class MyTestCase(unittest.TestCase):     ... 
like image 31
warvariuc Avatar answered Oct 05 '22 07:10

warvariuc