运行nosetests
时出现了一个奇怪的错误:
======================================================================
ERROR: Extract test data from tarball.
----------------------------------------------------------------------
TypeError: extract_test_data() missing 1 required positional argument: 'calling_file'
有问题的代码分为两个文件:
测试/ core.py
class CoreTestCase(unittest.TestCase):
@classmethod
def extract_test_data(cls, calling_file, base='data', name_only=False):
"""Extract test data from tarball.
...
"""
...
测试/.../ test_this.py
class TestThis(core.CoreTestCase):
"""Run some tests."""
@classmethod
def setUpClass(cls):
cls.TESTDAT_DIR = cls.extract_test_data(__file__)
导入等正常工作,unittest
没有任何问题。但出于某种原因,nose
正在破坏呼叫。
我已经尝试了以下所有方法:
cls.TESTDAT_DIR = cls.extract_test_data(calling_file=__file__)
cls.TESTDAT_DIR = cls.extract_test_data(cls,__file__)
cls.TESTDAT_DIR = cls.extract_test_data(cls, calling_file=__file__)
然后我仍然得到一个奇怪的混蛋:
TypeError: extract_test_data() got multiple values for argument 'calling_file'
AttributeError: type object 'TestThis' has no attribute 'TESTDAT_DIR'
答案 0 :(得分:4)
nose
正在尝试运行extract_test_data
,就像它是一个单元测试一样。重命名它以排除令牌test
或将其添加到extract_test_data
:
from nose.tools import nottest
class CoreTestCase(unittest.TestCase):
@nottest
@classmethod
def extract_test_data(cls, calling_file, base='data', name_only=False):
"""Extract test data from tarball.
...
"""
...
编辑:link到文档,其中解释说,默认情况下,testMatch
正则表达式将运行has test or Test at a word boundary or following a - or _