nose-devs/nose — Issue #341: Functions with module_name =/= func_compat_name are not recognized.
Author: jpellerin
Created: 2011-12-14 16:08:34+00:00
State: open

Hello,
today I wanted to fool around a bit with higher order functions to tidy up
my testcases, However I fell straight on my face :)

Consider the following test case:

----->8-------
def bar():
print "test called"

foo_test = bar
-----8<-------
This pattern occurs for example when using decorators or higher order
functions. In my understanding of nose, foo_test should be executed,
because it matches the (default) testMatch-pattern.

However, running nose (the development snapshot from just a minuge ago)
results in this:
----->8-----
nosetests --where=/home/hk/code/bug_demonstration/

----------------------------------------------------------------------
Ran 0 tests in 0.001s

OK
-----8<-----

This is clearly not wanted. :)

So, wanting to present a good testcase, I fired up nosetests with a log of
verbosity. This includes the following lines:
-----8<------
nose.selector: DEBUG: wantModule ? True
nose.selector: DEBUG: wantFunction ? None
nose.selector: DEBUG: wantFunction ? None
------>8------

Checking the nose.selector.Selector-source, the error was easy to spot:
-----8<------
if hasattr(function, 'compat_func_name'):
funcname = function.compat_func_name
else:
funcname = function.__name__
----->8------

Basically, this assumes that the assigned name in the module and the name
of the function are the same, which is not the case, if functions are
assigned to different names. A simple fix would be to include the name of
the function as a parameter to the wantFunction method, so the function
name is ignored, but the actual in-module name is ignored.
I am not sure if there are horrible edge cases where this breaks, but I
still attached a patch which does exactly this :)

Regards,
Harald K.

Google Code Info:
Issue #: 282
Author: har...@freenet.de
Created On: 2009-07-30T19:22:45.000Z
Closed On: