802_traceback.py 429 B

1234567891011121314151617181920212223
  1. import traceback
  2. import sys
  3. if sys.argv[0].endswith('.pyc'):
  4. exit()
  5. try:
  6. a = {'123': 4}
  7. b = a[6]
  8. except KeyError:
  9. actual = traceback.format_exc()
  10. expected = '''Traceback (most recent call last):
  11. File "tests/802_traceback.py", line 9
  12. b = a[6]
  13. KeyError: 6'''
  14. if actual != expected:
  15. print('--- ACTUAL RESULT -----')
  16. print(actual)
  17. print('--- EXPECTED RESULT ---')
  18. print(expected)
  19. exit(1)