I\'m using Python\'s unittest
library and all the tests succeed, but I still get a traceback and I can\'t understand how I can fix the problem.
sys.exit(not self.result.wasSuccessful())
I ran into this when I assumed my __main__.py
in my Python package would always have the __name__
, "__main__"
- but when I ran my unittests through discovery there, I found that they would be executed but with a different __name__
- "package.__main__"
.
Therefore I did need the following in my __main__.py
just like in simple Python scripts:
if __name__ == '__main__':
main()
instead of just
main()
If the main
is unittest.main
, call it with
if __name__ == '__main__':
main(exit=False)
if you want the process to stick around in interactive mode if you're calling
python -im package_name
If you're using:
python -m unittest discover
then I don't think exit=False
should matter.