pombreda / python-nose

Automatically exported from code.google.com/p/python-nose
0 stars 0 forks source link

Test discovery fails when importing functions to test module #410

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Write module with a function which has the word 'test' in the name e.g

module uut.py
-----------------
def foo_test(parameter1, parameter2):
    pass

2. Write a unit test for it
import unittest
from uut import foo_test

class Test(unittest.TestCase):

    def testName(self):
        foo_test('foo', 'bar')

3. Run test with nose

What is the expected output? What do you see instead?
I expect the test to execute without errors. Instead I get this output:

C:\Documents and Settings\matuusit\workspace\NoseDiscovery\src>nosetests tests
.E
======================================================================
ERROR: tests.uut_test.foo_test
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Apps\python\lib\site-packages\nose-0.11.4-py2.6.egg\nose\case.py", line 186, in runTest
    self.test(*self.arg)
  File "C:\Apps\python\lib\site-packages\nose-0.11.4-py2.6.egg\nose\util.py", line 634, in newfunc
    return func(*arg, **kw)
TypeError: foo_test() takes exactly 2 arguments (0 given)

----------------------------------------------------------------------
Ran 2 tests in 0.000s

FAILED (errors=1)

What version of the product are you using? On what operating system?
nosetests-script.py version 0.11.4 on Windows XP

Please provide any additional information below.
I can work around this problem by importing the module and using:
uut.foo_test('foo', 'bar')

Original issue reported on code.google.com by uusitalo...@gmail.com on 15 Apr 2011 at 6:59

Attachments:

GoogleCodeExporter commented 9 years ago
This isn't a bug -- foo_test is a function that nose would normally collect as 
a test because its name matches the testMatch regex. If you want to avoid 
having it collected you can rename it, or mark it as a non-test by setting 
foo_test.__test__ = False -- or as you said, by not importing test-like 
functions into the top level of a test module.

Original comment by jpelle...@gmail.com on 15 Apr 2011 at 1:04