Specifying names on the command line, like the other answers, says this is helpful and helpful. However, when I am in the process of writing tests, I often find that I want to run only the tests that I work on, and the names that I have to write on the command line become quite long and cumbersome to write, In this case, I prefer use custom decorator and flag.
I define wipd ("work in progress decorator") as follows:
from nose.plugins.attrib import attr def wipd(f): return attr('wip')(f)
This defines the @wipd decorator, which will set the wip attribute on the objects that it decorates. For example:
import unittest class Test(unittest.TestCase): @wipd def test_something(self): pass
Then -a wip can be used on the command line to narrow down the execution of the test to those marked with @wipd .
Note on the names ...
I use the name @wipd for the decorator, not @wip to avoid such a problem:
import unittest class Test(unittest.TestCase): from mymodule import wip @wip def test_something(self): pass def test_something_else(self): pass
import will make the wip decorator a member of the class, and all tags in the class will be selected. The attrib plugin checks the parent class of the test method to see if the selected attribute also exists there, and attributes created and tested with attrib do not exist in isolated space. Therefore, if you test with -a foo and your class contains foo = "platypus" , then all tests in the class will be selected by the plugin.
Louis Jul 08 '16 at 15:09 2016-07-08 15:09
source share