sách gpt4 ai đã đi

python - Nose 测试和类方法

In lại 作者:行者123 更新时间:2023-11-28 22:31:10 25 4
mua khóa gpt4 Nike

Khi tôi chạy nosetests 时出现奇怪的错误:

======================================================================
ERROR: Extract test data from tarball.
-----------------------------------------------------------------------------------
TypeError: extract_test_data() missing 1 required positional argument: 'calling_file'

有问题的代码分为两个文件:

测试/核心.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'

1 Câu trả lời

nose 正在尝试像运行单元测试一样运行 extract_test_data。重命名它以排除 token Bài kiểm tra 或将其添加到 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.
...
"""
...

biên tập:liên kết在文档中解释说,默认情况下,testMatch 正则表达式将运行任何 在单词边界或 - 或 _ 之后具有 test 或 Test 的函数

关于python - Nose 测试和类方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41746861/

25 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com