test_crashers.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # Tests that the crashers in the Lib/test/crashers directory actually
  2. # do crash the interpreter as expected
  3. #
  4. # If a crasher is fixed, it should be moved elsewhere in the test suite to
  5. # ensure it continues to work correctly.
  6. import unittest
  7. import glob
  8. import os.path
  9. import test.support
  10. from test.support.script_helper import assert_python_failure
  11. CRASHER_DIR = os.path.join(os.path.dirname(__file__), "crashers")
  12. CRASHER_FILES = os.path.join(glob.escape(CRASHER_DIR), "*.py")
  13. infinite_loops = ["infinite_loop_re.py", "nasty_eq_vs_dict.py"]
  14. class CrasherTest(unittest.TestCase):
  15. @unittest.skip("these tests are too fragile")
  16. @test.support.cpython_only
  17. def test_crashers_crash(self):
  18. for fname in glob.glob(CRASHER_FILES):
  19. if os.path.basename(fname) in infinite_loops:
  20. continue
  21. # Some "crashers" only trigger an exception rather than a
  22. # segfault. Consider that an acceptable outcome.
  23. if test.support.verbose:
  24. print("Checking crasher:", fname)
  25. assert_python_failure(fname)
  26. def tearDownModule():
  27. test.support.reap_children()
  28. if __name__ == "__main__":
  29. unittest.main()