File: test_clean_traceback.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
  • size: 9,264 kB
  • sloc: python: 21,500; makefile: 4
file content (56 lines) | stat: -rw-r--r-- 1,620 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""In this file, we test to ensure the traceback is properly trimmed
of all ignored files.
"""

import friendly_traceback


def test_uncleaned_traceback():
    """Assert this test filename appear in tracebacks if we don't exclude
    it.
    """
    friendly_traceback.install(redirect="capture")
    old_debug = friendly_traceback.debug_helper.DEBUG
    friendly_traceback.debug_helper.DEBUG = False

    try:
        from . import raise_exception
    except ValueError:
        friendly_traceback.explain_traceback()

    output = friendly_traceback.get_output()
    assert "test_clean_traceback" in output
    assert "André" in output

    # cleanup for other tests
    friendly_traceback.uninstall()
    friendly_traceback.debug_helper.DEBUG = old_debug


def test_cleaned_traceback():
    """Assert this test filename does not appear in tracebacks if we
    exclude it.
    """
    friendly_traceback.install(redirect="capture")
    friendly_traceback.exclude_file_from_traceback(__file__)
    old_debug = friendly_traceback.debug_helper.DEBUG
    friendly_traceback.debug_helper.DEBUG = False

    try:
        from . import raise_exception
    except ValueError:
        friendly_traceback.explain_traceback()

    output = friendly_traceback.get_output()
    assert "test_clean_traceback" not in output
    assert "André" in output

    # cleanup for other tests
    friendly_traceback.path_info.include_file_in_traceback(__file__)
    friendly_traceback.uninstall()
    friendly_traceback.debug_helper.DEBUG = old_debug


if __name__ == "__main__":
    test_uncleaned_traceback()
    test_cleaned_traceback()