Setuptools - 当测试不在主目录中时如何 运行 unittest 测试套件?
Setuptools - how to run unittest test suite when tests are not in main directory?
我有以下模块结构:
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',
我有以下模块结构:
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',