PyCharm:单独工作的测试,在组中运行时找不到文件

问题描述 投票:0回答:1

在我的Python项目中,我有一组单元测试,这些单元测试从数据子目录中的文件中加载一些数据。

在PyCharm(社区2019.3)中,单独运行每个组件都可以正常工作,但是通过在Project边栏结构的'tests'目录中单击鼠标右键来分组运行它们时,它们会失败。

目录结构(仅显示一个示例):

Project dir structure

我加载了一些模拟文件,如某些.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?所示:]

我做了配置检查:

Run Configurations

以下:PyCharm unittests only work individually

Python Integrated Settings

以下:Pycharm and unittest does not work

我找不到任何问题,请问有人有什么想法吗?

在我的Python项目中,我有一组单元测试,这些单元测试从数据子目录中的文件中加载一些数据。在PyCharm(社区2019.3)中,单独运行它们每个都可以工作,但是它们...

unit-testing pycharm python-unittest
1个回答
0
投票

在Windows 10上工作,对我来说解决的是简单地从WORKING目录

© www.soinside.com 2019 - 2024. All rights reserved.