File: test_exception_note.py

package info (click to toggle)
python-friendly-traceback 0.7.62%2Bgit20240811.d7dbff6-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,264 kB
  • sloc: python: 21,500; makefile: 4
file content (25 lines) | stat: -rw-r--r-- 780 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import sys
import friendly_traceback as ft


def test_exception_note():
    exc = ValueError("This is an exception.")
    if sys.version_info >= (3, 11):
        exc.add_note("This is a note.")
        try:
            raise exc
        except ValueError:
            ft.explain_traceback(redirect="capture")
            result = ft.get_output()
            assert "* This is a note." in result
    else:
        try:
            exc.add_note("This is a note.")
        except AttributeError:
            ft.explain_traceback(redirect="capture")
            result = ft.get_output()
            if ft.get_lang() == "en":
                assert (
                    "`add_note()` is only allowed for Python version 3.11 and newer."
                    in result
                )