| 1 | import sys |
| 2 | import friendly_traceback as ft |
| 3 | |
| 4 | |
| 5 | def test_exception_note(): |
| 6 | exc = ValueError("This is an exception.") |
| 7 | if sys.version_info >= (3, 11): |
| 8 | exc.add_note("This is a note.") |
| 9 | try: |
| 10 | raise exc |
| 11 | except ValueError: |
| 12 | ft.explain_traceback(redirect="capture") |
| 13 | result = ft.get_output() |
| 14 | assert "* This is a note." in result |
| 15 | else: |
| 16 | try: |
| 17 | exc.add_note("This is a note.") |
| 18 | except AttributeError: |
| 19 | ft.explain_traceback(redirect="capture") |
| 20 | result = ft.get_output() |
| 21 | if ft.get_lang() == "en": |
| 22 | assert ( |
| 23 | "`add_note()` is only allowed for Python version 3.11 and newer." |
| 24 | in result |
| 25 | ) |