Search code examples
pythonpycharmpython-unittest

PyCharm and unittest won't run


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

Here is my code :

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()

Here is All the stuff PyCharm give me

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

It also says

AttributeError: class TestLoader has no attribute '__init__'

And the event log :

2:14:28 PM Empty test suite

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 :

  • Setting->Python Integrated Tools->Package requirements file: <PROJECT_HOME>/src/test
  • Default test runner: Unittests
  • pyunit 1.4.1 Is installed

EDIT: 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()

Solution

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

    enter image description here