gpt4 book ai didi

python - 'MyTestClass' 的实例没有 'assertEqual' 成员 pylint(无成员)VScode

转载 作者:行者123 更新时间:2023-12-04 08:04:03 27 4
gpt4 key购买 nike

我正在尝试为 python 编程设置我的 VScode 环境(我一直使用它直到现在只编写 c++ 代码)。我设置了非常简单的“Hello world”程序并为其编写了虚拟测试:

from problems.hello_world import HelloWorld

class SimpleTest():
def setUp(self):
self.hello = HelloWorld()

def test_dummy(self):
self.assertEqual(True,False)

这个测试通过了,这是错误的,它应该失败!但是我的 VScode 提示(在我调用 assertEqual 的最后一行) Instance of 'SimpleTest' has no 'assertEqual' member pylint (no-member) .
它还在导入行中提示 Unable to import 'problems.hello_world'pylint(import-error) .
我的 python 二进制文件和 python 测试都在名为问题的同一个文件夹中。
我正在使用 bazel build 和 python 3.7 版本。我无法弄清楚我的 VScode python 设置有什么问题,或者任何问题。使用 C++ 环境,它可以完美运行。
在我的工作区 settings.json 中,我启用了 pylint,这是它的内容:
{
"python.linting.pylintEnabled": true,
"python.linting.enabled": true,

}
在我的 settings.json 文件中只有两行。对于我的 C++ 程序,我使用单独的工作区(可能是问题所在?)。
感谢帮助!

最佳答案

你必须实现一个 unittest.TestCase 的子类, 喜欢

from problems.hello_world import HelloWorld
from unittest import TestCase


class SimpleTest(TestCase):
def setUp(self):
self.hello = HelloWorld()

def test_dummy(self):
self.assertEqual(True,False)

关于python - 'MyTestClass' 的实例没有 'assertEqual' 成员 pylint(无成员)VScode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66307322/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com