gpt4 book ai didi

Python 单元测试 : AttributeError: no attribute 'assertTrue' when running on Linux

转载 作者:太空狗 更新时间:2023-10-29 11:12:17 25 4
gpt4 key购买 nike

我在 Python 中运行一些非常简单的单元测试,发现 assertTrue() 函数不起作用,而在同一个测试用例中 assertEqual() 工作正常。为了简化问题,我将代码最小化为以下内容:

import unittest

class easyTest (unittest.TestCase):
def setUp(self):
pass

def test_true(self):
self.assertTrue(True)

if __name__ == "__main__":
unittest.main()

这批代码在我的 Windows 笔记本电脑上运行完美,但返回

AttributeError: easyTest instance has no attribute 'assertTrue'

当我尝试在 Linux 上运行它时。

在两台笔记本电脑上,我都在 IDE pyCharm Community Edition 2017.1.4 上使用 python 2.7.6。我的 Linux 笔记本电脑运行的是 Ubuntu 14.04.1

我在这里发现了一个非常相似的问题: AttributeError: TestSwitch instance has no attribute 'assertTrue'由于似乎没有人回答这个问题,我在这里再次提问,希望得到一些突出的答案。

最佳答案

根据您的评论,您使用的单元测试版本是(长期弃用的)独立 PyUnit 1.4.1 包。作为package's homepage mentions :

Unless you're stuck in the year 2000, PyUnit is in your Python standard library as module unittest.

事实上,unittest 已添加到 Python 2.1 中的标准库中。

IOW,除非您坚持使用过时的遗留代码库(使用 Python < 2.1!),否则您应该只卸载 PyUnit,您的问题就会得到解决。

关于Python 单元测试 : AttributeError: no attribute 'assertTrue' when running on Linux,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45297734/

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