PyCharm测试右键运行:builtins.tuple AttributeError对象没有属性

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

更新和导入一些项目后,从 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>)

它创建的运行/调试配置是:

  • “Python 测试”一个
  • 自动检测的目标
    Script path
    ”到
    /home/user123/development/Project456/tests/test_the_tester.py
  • Python 解释器
    Project Default
    (
    /usr/bin/python3.8
    )
  • 工作目录
    /home/user123/development/Project456/tests/
  • 选择“将内容根添加到 PYTHONPATH”和“将源根添加到 PUTHONPATH”这两个选项
pycharm python-unittest
1个回答
1
投票
我不确定您是否找到了解决方案,在将测试文件的名称更改为以“test_”开头并在“setUp”方法中启动测试类后,我解决了同样的问题。

就我而言,我的测试代码在安装了一些库后完全无法工作,错误消息如下:

Error Traceback (most recent call last): Failure: builtins.tuple:
我希望你已经解决了这个问题!

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