Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Test discovery fails when importing functions to test module #127

Closed
jpellerin opened this Issue · 1 comment

1 participant

@jpellerin
Owner

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

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

class Test(unittest.TestCase):

def testName(self):
    foo_test('foo', 'bar')
  1. 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')

Google Code Info:
Issue #: 410
Author: uusitalo...@gmail.com
Created On: 2011-04-15T06:59:12.000Z
Closed On: 2011-04-15T13:04:58.000Z

@jpellerin jpellerin was assigned
@jpellerin
Owner

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.

Google Code Info:
Author: jpelle...@gmail.com
Created On: 2011-04-15T13:04:58.000Z

@jpellerin jpellerin closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.