Search code examples
pythonunit-testingnose

How to skip tests containing certain text in their docstring?


I would like to store hints inside each test method's docstring, so the testloader can include or exclude the test based on those hints. Something like this:

def test_login_with_valid_credentials(self):
    '''#functional #security #nondestructive'''
    # code goes here

Then the testloader would discover all tests containing the substring '#functional' or whatever.

I'm trying to avoid using decorators for this purpose, because I think using docstrings would be more flexible. (Maybe I'm wrong.)

Being new to nose, I would appreciate any help. Thanks!


Solution

  • In case anyone is wondering, this is the actual syntax:

    @attr(functional=True, security=True, nondestructive=False)
    

    And the tests are invoked thusly:

    /usr/local/bin/nosetests -v --exe -a functional -w test_directory