gpt4 book ai didi

python - Setuptools - 当测试不在主目录中时如何运行 unittest 测试套件?

转载 作者:行者123 更新时间:2023-11-28 20:37:40 24 4
gpt4 key购买 nike

我有以下模块结构:

main
->module
--->tests
----->test_module.py
--->module.py
->setup.py

我使用 unittest 包实现了单元测试。关注此 answer 时我将我的 setup.py 文件设置为:

from setuptools import setup

setup(
name='module',
packages=['module', ],
test_suite='module/tests',
)

产生了以下错误信息:

====================================================================== ERROR: tests (unittest.loader._FailedTest) ---------------------------------------------------------------------- ImportError: Failed to import test module: tests Traceback (most recent call last): File "/opt/conda/lib/python3.6/unittest/loader.py", line 153, in loadTestsFromName module = import(module_name) ModuleNotFoundError: No module named 'tests/module'


Ran 1 test in 0.000s

FAILED (errors=1) Test failed: error: Test failed:

当设置 test_suite='tests 我有:

====================================================================== ERROR: tests (unittest.loader._FailedTest) ---------------------------------------------------------------------- ImportError: Failed to import test module: tests Traceback (most recent call last): File "/opt/conda/lib/python3.6/unittest/loader.py", line 153, in loadTestsFromName module = import(module_name) ModuleNotFoundError: No module named 'tests'


Ran 1 test in 0.000s

FAILED (errors=1) Test failed: error: Test failed:

有人可以帮我解决这个问题吗?

最佳答案

test_suite是测试package的名称(Python点分语法),不是目录路径,所以语法必须是

test_suite='module.tests',

关于python - Setuptools - 当测试不在主目录中时如何运行 unittest 测试套件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48126918/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com