diff --git a/nose/case.py b/nose/case.py index e5a407a0..c585c2b2 100644 --- a/nose/case.py +++ b/nose/case.py @@ -199,7 +199,7 @@ def runTest(self): def shortDescription(self): if hasattr(self.test, 'description'): return self.test.description - func, arg = self._descriptors() + func = self._descriptor() doc = getattr(func, '__doc__', None) if not doc: doc = str(self) @@ -277,32 +277,27 @@ def tearDown(self): try_run(self.test, names) def __str__(self): - func, arg = self._descriptors() + func = self._descriptor() if hasattr(func, 'compat_func_name'): name = func.compat_func_name else: name = func.__name__ name = "%s.%s" % (func.__module__, name) - if not arg == '()': - name = "%s%s" % (name, arg) + if not self.arg_repr == '()': + name = "%s%s" % (name, self.arg_repr) # FIXME need to include the full dir path to disambiguate # in cases where test module of the same name was seen in # another directory (old fromDirectory) return name __repr__ = __str__ - def _descriptors(self): - """Get the descriptors of the test function: the function and - arguments that will be used to construct the test name. In - most cases, this is the function itself and no arguments. For - tests generated by generator functions, the original - (generator) function and args passed to the generated function - are returned. + def _descriptor(self): + """Get the descriptor of the test method. + + If a `descriptor` was specified for __init__, then it is returned, else + the test method (callable object) is returned. """ - if self.descriptor: - return self.descriptor, self.arg_repr - else: - return self.test, self.arg_repr + return self.descriptor if self.descriptor is not None else self.test class MethodTestCase(TestBase): @@ -351,7 +346,7 @@ def __init__(self, method, test=None, arg=tuple(), descriptor=None): TestBase.__init__(self) def __str__(self): - func, arg = self._descriptors() + func = self._descriptor() if hasattr(func, 'compat_func_name'): name = func.compat_func_name else: @@ -359,8 +354,8 @@ def __str__(self): name = "%s.%s.%s" % (self.cls.__module__, self.cls.__name__, name) - if not arg == '()': - name = "%s%s" % (name, arg) + if not self.arg_repr == '()': + name = "%s%s" % (name, self.arg_repr) return name __repr__ = __str__ @@ -385,15 +380,10 @@ def setUp(self): def tearDown(self): try_run(self.inst, ('teardown', 'tearDown')) - def _descriptors(self): - """Get the descriptors of the test method: the method and - arguments that will be used to construct the test name. In - most cases, this is the method itself and no arguments. For - tests generated by generator methods, the original - (generator) method and args passed to the generated method - or function are returned. + def _descriptor(self): + """Get the descriptor of the test method. + + If a `descriptor` was specified for __init__, then it is returned, else + the test method (callable object) is returned. """ - if self.descriptor: - return self.descriptor, self.arg_repr - else: - return self.method, self.arg_repr + return self.descriptor if self.descriptor is not None else self.method