更新和导入一些项目后,从 Pycharm 运行后,我的测试会发生一些非常奇怪的事情。我已经修复了一般的unittest运行器配置,但是在运行单个测试时我无法做到这一点,无论是在配置中还是只需右键单击,这都非常舒服。
这是一个非常简单的示例代码:
import unittest
class TestTheTester(unittest.TestCase):
@classmethod
def setUpClass(cls) -> None:
cls.name = "TestTheTester"
def test_unittest(self):
self.assertEqual("TestTheTester", self.name)
从 Shell 运行它:
python3 -m unittest tests/test_the_tester.py
.
----------------------------------------------------------------------
Ran 1 test in 0.000s
OK
右键单击 PyCharm 来运行它(选项
"Run 'Python test in tests...'
):
/usr/bin/python3.8 /snap/pycharm-community/252/plugins/python-ce/helpers/pycharm/_jb_trialtest_runner.py --path /home/user123/development/Project456/tests/test_the_tester.py
Testing started at 10:26 ...
Launching trial with arguments --reporter=teamcity /home/user123/development/Project456/tests/test_the_tester.py in /home/user123/development/Project456/tests/
Error
Traceback (most recent call last):
Failure: builtins.tuple: (<class 'AttributeError'>, AttributeError("'TestTheTester' object has no attribute 'name'"), <traceback object at 0x7fc59e432f00>)
它创建的运行/调试配置是:
Script path
”到/home/user123/development/Project456/tests/test_the_tester.py
Project Default
(/usr/bin/python3.8
)/home/user123/development/Project456/tests/
就我而言,我的测试代码在安装了一些库后完全无法工作,错误消息如下:
Error
Traceback (most recent call last):
Failure: builtins.tuple:
我希望你已经解决了这个问题!