test_exit.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. __author__ = "leszek"
  2. import unittest
  3. class ExitTest(unittest.TestCase):
  4. def test_exit(self):
  5. try:
  6. exit()
  7. self.fail("Should not reach line after exit")
  8. except SystemExit as e:
  9. return
  10. self.fail("Test should have returned")
  11. def test_exit_not_exception(self):
  12. try:
  13. try:
  14. exit()
  15. except Exception as e:
  16. self.fail("except Exception should not catch SystemExit")
  17. self.fail("Should not reach line after exit")
  18. except SystemExit as e:
  19. return
  20. self.fail("Test should have returned")
  21. def test_exit_in_func(self):
  22. try:
  23. def foo():
  24. exit()
  25. exit()
  26. self.fail("Should not reach line after exit")
  27. except SystemExit as e:
  28. return
  29. self.fail("Test should have returned")
  30. def test_import_exit(self):
  31. try:
  32. import exiting_module
  33. self.fail("Should not reach line after import")
  34. except SystemExit as e:
  35. return
  36. self.fail("Test should have returned")
  37. if __name__ == "__main__":
  38. unittest.main()