Pycharm and unittest does not work

drgn picture drgn · Nov 27, 2013 · Viewed 29.2k times · Source

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

Is 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: /src/test Default test runner: Unittests pyunit 1.4.1 Is installed

Thank you for any kind of help.

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

Answer

binarysubstrate picture binarysubstrate · Jan 8, 2015

Although this wasn't the case with the original poster, I'd like to note that another thing that will cause this are test functions that don't begin with the word 'test.'

class TestSet(unittest.TestCase):

    def test_will_work(self):
        pass

    def will_not_work(self):
        pass