鼻子测试和类方法
Nosetests and classmethods
当我 运行 nosetests
:
时出现奇怪的错误
======================================================================
ERROR: Extract test data from tarball.
----------------------------------------------------------------------
TypeError: extract_test_data() missing 1 required positional argument: 'calling_file'
有问题的代码分为两个文件:
tests/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'
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 _
[=18= 的任何函数]
当我 运行 nosetests
:
======================================================================
ERROR: Extract test data from tarball.
----------------------------------------------------------------------
TypeError: extract_test_data() missing 1 required positional argument: 'calling_file'
有问题的代码分为两个文件:
tests/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'
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 _
[=18= 的任何函数]