PyCharm 和 unittest 不会运行 [英] PyCharm and unittest won't run

查看:57
本文介绍了PyCharm 和 unittest 不会运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了 PyCharm 3.0.1 的问题,我无法运行基本的单元测试.

I have a problem with PyCharm 3.0.1 I can't run basic unittests.

这是我的代码:

import unittest from MysqlServer import MysqlServer


class MysqlServerTest(unittest.TestCase):


    def setUp(self):
        self.mysqlServer = MysqlServer("ip", "username", "password", "db", port)


    def test_canConnect(self):
        self.mysqlServer.connect()
        self.fail()


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

这是 PyCharm 给我的所有东西

Here is All the stuff PyCharm give me

无法将测试报告器附加到测试框架或测试框架意外退出

Unable to attach test reporter to test framework or test framework quit unexpectedly

它也说

AttributeError: class TestLoader has no attribute '__init__'

还有事件日志:

2:14:28 PM Empty test suite

问题是当我手动运行 Python 文件时(使用 PyCharm,作为脚本)

The problem is when I run manually the Python file (with PyCharm, as a script)

Ran 1 tests in 0.019s

FAILED (failures=1)

这很正常,我故意让测试失败.我对发生的事情有点不知所措.这里有更多信息:

Which is normal I make the test fail on purpose. I am a bit clueless on what is going on. here more information :

  • 设置->Python集成工具->包需求文件:<PROJECT_HOME>/src/test
  • 默认测试运行器:单元测试
  • pyunit 1.4.1 已安装

unitests.py 的基本用法也会发生同样的事情

Same thing happen with the basic usage from unitests.py

import unittest


class IntegerArithmenticTestCase(unittest.TestCase):
def testAdd(self):  ## test method names begin 'test*'
    self.assertEquals((1 + 2), 3)
    self.assertEquals(0 + 1, 1)

def testMultiply(self):
    self.assertEquals((0 * 10), 0)
    self.assertEquals((5 * 8), 40)


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

推荐答案

这可能是因为您没有在设置对话框中正确设置测试框架.

This is probably because you did not set your testing framework correctly in the settings dialogue.

这篇关于PyCharm 和 unittest 不会运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆