【发布时间】:2020-01-28 15:36:32
【问题描述】:
在我的 Python 项目中,我有一组单元测试,它们从数据子目录中的文件加载一些数据。
在 PyCharm (Community 2019.3) 中,单独运行它们中的每一个都可以工作,但是在组中运行它们时它们会失败,通过在项目侧边栏结构的“测试”目录中单击鼠标右键。
Dir 结构(仅显示 1 个示例):
我加载了一些模拟文件,例如一些 .ini 文件:单独执行时,它们可以工作,而在组中执行时,它们会失败。 输出:
--- Logging error ---
Traceback (most recent call last):
Failure
Traceback (most recent call last):
File "/usr/lib/python3.6/unittest/suite.py", line 163, in _handleClassSetUp
setUpClass()
File "/home/.../tests/test_ConnectorUtils.py", line 22, in setUpClass
with open("data/settings.ini") as fsettings:
FileNotFoundError: [Errno 2] No such file or directory: 'data/settings.ini'
单独运行时:
Testing started at 16:07 ...
/usr/bin/python3.6
/snap/pycharm-community/175/plugins/python-ce/helpers/pycharm/_jb_unittest_runner.py
--path /home/.../tests/test_ConnectorUtils.py
Launching unittests with arguments python -m
unittest /home/.../tests/test_ConnectorUtils.py in /home/.../tests
Ran 5 tests in 0.009s
OK
不确定它是否相关,但在我的文件不是由 test_ 开始之前,所以 Pycharm 没有检测到任何测试,所以我重命名了它们,正如它所建议的那样:Pycharm - no tests were found?
我做的配置检查:
关注:PyCharm unittests only work individually
关注:Pycharm and unittest does not work
我找不到任何问题,请问有人有什么想法吗?
【问题讨论】:
标签: unit-testing pycharm python-unittest