I'm trying to use the "unittest" module in Python version 3.
I tried to verify if it's correctly installed with:
try:
import unittest
print("imported")
except ImportError as e:
print("no")
The module will be imported correctly, but, if I try to access to its own methods including "main()" and "TestCase" will be raised the exception:
Command run: python3 -m testunit.py
testunit.py:
import unittest
import calculation
class TestCalc(unittest.TestCase):
def test_add(self):
result = calculation.add(10,50)
self.assertEquals(result,60)
if __name__ == '__main__':
unittest.main(defaultTest='suite')
Error given:
AttributeError: module 'unittest' has no attribute 'main'
Others results:
If I try to run the command python3 -m unittest it should give as output "RAN 0 tests in 0s", but no.
No output will be given.
In a nutshell the module is correctly installed but seems to not working at all.
Stacktrace given from the error:
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/runpy.py", line 183, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/runpy.py", line 109, in _get_module_details
__import__(pkg_name)
File "/Users/istorn/testunit.py", line 3, in <module>