1

nosetest uses heuristics to identify which functions are testcases. This can get awkward when importing a method with an ambiguous name for testing, e.g.:

foo/foo.py

def get_test_case(text):
    return "xyz"

(Note directory foo is excluded, this is not about nosetests identifying foo/foo.py as a testcase)

tests/test_foo.py

import unittest

# causes TypeError: get_test_case() missing 1 required positional argument: 'text'
from foo.foo import get_test_case

class TestTestCasesReader(unittest.TestCase):

     def test_get_test_case(self):
         self.assertEquals(get_test_case("fooBar"), ...)

I know I can do this workaround in the test:

import unittest
import foo.foo

# ...
        self.assertEquals(foo.get_test_case("fooBar"), ...)

but it feels like there should be a better way to tell nosetest to lay off that get_test_case function.

Obviously I could also rename get_test_case to hide it from nosetests, that's not the answer I am looking for though.

tkruse
  • 10,222
  • 7
  • 53
  • 80

1 Answers1

1

This is a relevant question: Getting nose to ignore a function with 'test' in the name

Two solutions were suggested in the question

  1. using the nottest decorator in the module that defines get_test_case.
from nose.tools import nottest

@nottest
def get_test_case(text):
    return "xyz"
  1. using nottest in test code
import unittest
from nose.tools import nottest

from foo.foo import get_test_case
get_test_case = nottest(get_test_case)

class TestTestCasesReader(unittest.TestCase):

     def test_get_test_case(self):
         self.assertEquals(get_test_case("fooBar"), ...)
ichyo
  • 26
  • 2
  • 2