Getting nose to ignore a function with 'test' in the name

前端 未结 2 374
忘了有多久
忘了有多久 2021-01-04 07:18

The nose discovery process finds all modules whose name starts with test, and within them all functions which have test in the name an

相关标签:
2条回答
  • 2021-01-04 07:43

    Nose has a nottest decorator. However, if you don't want to apply the @nottest decorator in the module you are importing from you can also simply modify the method after the import. It may be cleaner to keep unit test logic close to the unit test itself.

    from foo.accounts import make_test_account
    # prevent nose test from running this imported method
    make_test_account.__test__ = False
    

    You can still use nottest but it has the same effect:

    from nose.tools import nottest
    from foo.accounts import make_test_account
    # prevent nose test from running this imported method
    make_test_account = nottest(make_test_account)
    
    0 讨论(0)
  • 2021-01-04 07:47

    Tell nose that the function is not a test - use the nottest decorator.

    # module foo.accounts
    
    from nose.tools import nottest
    
    @nottest
    def make_test_account():
        ...
    
    0 讨论(0)
提交回复
热议问题