Getting the nose to ignore the function with the "test" in the name

The nose detection process finds all the modules whose name begins with test , and inside them all the functions that have test in the name and try to run them as unit tests. See http://nose.readthedocs.org/en/latest/man.html

I have a function named make_test_account in the accounts.py file. I want to test this function in a test module called test_account . So at the beginning of this file I do:

 from foo.accounts import make_test_account 

But now I find that the nose considers the make_test_account function as a unit test and tries to run it (which fails because it does not pass into any parameters that are required).

How can I make sure the nose ignores this feature? I would prefer to do this in such a way that I can call the nose like nosetests without command line arguments.

+5
source share
2 answers

The nose has a nottest decorator. However, if you do not want to use the @nottest decorator in the module you are importing, you can also simply change the method after importing. It may be cleaner to keep the 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) 
+4
source

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

 # module foo.accounts from nose.tools import nottest @nottest def make_test_account(): ... 
+5
source

Source: https://habr.com/ru/post/1235409/


All Articles