George V. Reilly

Nose Test Discovery

Nose is nicer testing for Python

I figured out why I saw the following error every time I ran Nose:

ERROR: Failure: TypeError (type() takes 1 or 3 arguments)
Traceback (most recent call last):
  File ".../lib/python2.7/site-packages/nose-1.3.7-py2.7.egg/nose/", line 523, in makeTest
    return self._makeTest(obj, parent)
  File ".../lib/python2.7/site-packages/nose-1.3.7-py2.7.egg/nose/", line 582, in _makeTest
    return MethodTestCase(obj)
  File ".../lib/python2.7/site-packages/nose-1.3.7-py2.7.egg/nose/", line 345, in __init__
    self.inst = self.cls()
TypeError: type() takes 1 or 3 arguments

It turns out that one module was importing a class called TestApi which had a class­method called run_in­te­gra­tion_tests. The module itself had no tests; it just declared a class called TestO­b­fus­cat­ed­Mix­in, which used some other class­methods on TestApi. Nose’s test discovery considered run_in­te­gra­tion_tests to be a test because both the class and the function matched the testMatch regular expression, i.e., a name that has test or Test at a word boundary or following a - or _.

I renamed it to run_in­te­gra­tion_t3sts [sic]. It’s hard to find a good synonym for "tests".

Tip: to run a particular test from the command line:

nosetests path/to/

That is, pathname COLON classname DOT testname

blog comments powered by Disqus
Review: Sherlock Holmes (2010 film) » « Review: The Fuller Memorandum