File: test_flush.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 (22 lines) | stat: -rw-r--r-- 691 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
import friendly_traceback


def test_flush():
    try:
        b = c
    except Exception:
        friendly_traceback.explain_traceback(redirect="capture")
    result = friendly_traceback.get_output(flush=False)
    assert "NameError: name 'c' is not defined" in result
    result1 = friendly_traceback.get_output()  # flushes
    assert "NameError: name 'c' is not defined" in result1
    result2 = friendly_traceback.get_output()  # returns empty string
    assert not result2


if __name__ == "__main__":
    result, result2 = test_flush()
    print("Before flush:\n", "-" * 50)
    print(result)
    print("=" * 50, "\nAfter flush, should have empty string:\n")
    print(repr(result2))