I'm getting a cryptic (and unhelpful, probably false) error in my nosetests script in this format (function name has been anonymized to "some_function", that's the one I wrote and nose isn't invoking it correctly):
File "/Users/REDACTED/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
self.test(*self.arg)
File "/Users/REDACTED/lib/python2.7/site-packages/nose/util.py", line 620, in newfunc
self.test(*self.arg)
TypeError: some_function() takes exactly 1 argument (0 given)
This error isn't useful as it doesn't provide details on the source of the problem. Additionally, manually running through all the testing functions in the test script (example: nosetests tests/test_myprogram.py:test_some_function()) produces no errors.
I also manually checked the tests in order for variables that are shared across tests (to verify that leftover data changes from a previous test aren't corrupting later tests).
Due diligence: All searches on the topic turn up nothing useful:
Found the problem.
https://github.com/nose-devs/nose/issues/294
There's an insidious issue with nosetests where if you import functions with "test" in their name into a test script, they get incorrectly flagged as test functions and run as such. If they take any arguments, nosetests will run them with none and immediately produce an untraceable error.
For example:
foo.py:
def prepare_test_run_program(params):
# some programming here, could be anything
print("...")
if (some conditions): # pseudocode, use your imagination
return True
else:
return False
And now a matching test script test_foo.py:
from foo import prepare_test_run_program
from nose.tools import assert_equal
def test_prepare_test_run_program():
params = ... # some parameter settings to test
assert_equal(prepare_test_run_program(params), True)
Now run the test script from the command line:
nosetests test_foo.py
and you will get an TypeError traceable only to runTest and newFunc (as mentioned in the question):
TypeError: prepare_test_run_program() takes at least 1 argument (0 given)
The best way to fix this: Set the test variable in the function mistaken for a test to False. The link I mentioned doesn't properly display the double underscores due to site-specific formatting, so here's my modified example test_foo.py, fixed for nosetests:
from foo import prepare_test_run_program
from nose.tools import assert_equal
prepare_test_run_program.__test__ = False # tell nose that this function isn't a test
def test_prepare_test_run_program():
params = ... # some parameter settings to test
assert_equal(prepare_test_run_program(params), True)