Pycharm 和 unittest 不起作用 [英] Pycharm and unittest does not work
问题描述
我在使用 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)
这是正常的,我故意让测试失败.我对正在发生的事情有点无能为力这里有更多信息:Setting->Python INtegrated Tools->Package requirements file:/src/test默认测试运行器:Unittestspyunit 1.4.1 已安装
Which is normal i make the test fail on purpose. I am a bit clueless on what is going on here more information : Setting->Python INtegrated Tools->Package requirements file: /src/test Default test runner: Unittests pyunit 1.4.1 Is installed
感谢您的任何帮助.
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屋!