Python Unittest: AttributeError: no 'assertTrue' attribute when running on Linux
I am running very simple unit tests in Python
and found that the function is assertTrue()
not working, but in the same test tag it assertEqual()
works fine. To simplify this problem, I have boiled down the code to this:
import unittest
class easyTest (unittest.TestCase):
def setUp(self):
pass
def test_true(self):
self.assertTrue(True)
if __name__ == "__main__":
unittest.main()
This series of codes works fine on my windows laptop but returns
AttributeError: easyTest instance has no attribute 'assertTrue'
when i try to run it on linux.
On both laptops, I use python 2.7.6
the IDE pyCharm Community Edition 2017.1.4
. My Linux laptop is workingUbuntu 14.04.1
I found a very similar question here: AttributeError: TestSwitch instance has no assertTrue attribute And since no one seems to be answering this question, I'm asking again here, hoping for some outstanding answers.
source to share
As per your comment, the version of unittest used is (standalone PyUnit 1.4.1
package (deprecated)). As shown in the home page:
If you're not stuck in 2000, PyUnit is in your Python standard library as a unittest module.
Indeed, it unittest
was added to stdlib in Python 2.1.
IOW, if you're not stuck with the old-fashioned legacy codebase (using Python <2.1!), You should simply uninstall PyUnit and your problem will be resolved.
source to share
Is it possible that you have a second module or unittest package in your python path?
If you created a unittest.py file or a unittest directory containing an init .py file , python might find that before it finds a normal module in the python standard library.
Naming a local unit or package unittest is equivalent to naming a list of local variables or dict or map; you mask the built-in name with a local override.
Rename this module or package to something else to fix this.
source to share