>>> import _colorize >>> save_colorize = _colorize.COLORIZE >>> _colorize.COLORIZE = False >>> test_exception_with_note('Note') Traceback (most recent call last): ... ValueError: Text Note >>> test_exception_with_note('Note') # doctest: +IGNORE_EXCEPTION_DET
(note)
| 3680 | |
| 3681 | |
| 3682 | def test_exception_with_note(note): |
| 3683 | """ |
| 3684 | >>> import _colorize |
| 3685 | >>> save_colorize = _colorize.COLORIZE |
| 3686 | >>> _colorize.COLORIZE = False |
| 3687 | |
| 3688 | >>> test_exception_with_note('Note') |
| 3689 | Traceback (most recent call last): |
| 3690 | ... |
| 3691 | ValueError: Text |
| 3692 | Note |
| 3693 | |
| 3694 | >>> test_exception_with_note('Note') # doctest: +IGNORE_EXCEPTION_DETAIL |
| 3695 | Traceback (most recent call last): |
| 3696 | ... |
| 3697 | ValueError: Text |
| 3698 | Note |
| 3699 | |
| 3700 | >>> test_exception_with_note('''Note |
| 3701 | ... multiline |
| 3702 | ... example''') |
| 3703 | Traceback (most recent call last): |
| 3704 | ValueError: Text |
| 3705 | Note |
| 3706 | multiline |
| 3707 | example |
| 3708 | |
| 3709 | Different note will fail the test: |
| 3710 | |
| 3711 | >>> def f(x): |
| 3712 | ... r''' |
| 3713 | ... >>> exc = ValueError('message') |
| 3714 | ... >>> exc.add_note('note') |
| 3715 | ... >>> raise exc |
| 3716 | ... Traceback (most recent call last): |
| 3717 | ... ValueError: message |
| 3718 | ... wrong note |
| 3719 | ... ''' |
| 3720 | >>> test = doctest.DocTestFinder().find(f)[0] |
| 3721 | >>> doctest.DocTestRunner(verbose=False).run(test) |
| 3722 | ... # doctest: +ELLIPSIS |
| 3723 | ********************************************************************** |
| 3724 | File "...", line 5, in f |
| 3725 | Failed example: |
| 3726 | raise exc |
| 3727 | Expected: |
| 3728 | Traceback (most recent call last): |
| 3729 | ValueError: message |
| 3730 | wrong note |
| 3731 | Got: |
| 3732 | Traceback (most recent call last): |
| 3733 | ... |
| 3734 | ValueError: message |
| 3735 | note |
| 3736 | TestResults(failed=1, attempted=...) |
| 3737 | |
| 3738 | >>> _colorize.COLORIZE = save_colorize |
| 3739 | """ |