AttributeError: ‘module’ object has no attribute ‘TestCase’

I have file with unittest named:

My code:

import unittest

class Test(unittest.TestCase):

    def myTest(self):
        a = 1
        self.assertEqual(a, 1)

if __name__ == '__main__':

When I press F5, I get an error:

Traceback (most recent call last):
  File "/home/mariusz/Pulpit/", line 1, in <module>
    import unittest
  File "/home/mariusz/Pulpit/", line 3, in <module>
AttributeError: 'module' object has no attribute 'TestCase'


You have a local file named that is being imported instead:


Rename that file or remove it altogether. Make sure you remove any corresponding unittest.pyc file in the same folder if it is there.

The file is masking the standard library package.

Leave a Reply

Your email address will not be published. Required fields are marked *