|
13 | 13 | from _pytest._code.code import ExceptionInfo
|
14 | 14 | from _pytest._code.code import FormattedExcinfo
|
15 | 15 | from _pytest._io import TerminalWriter
|
16 |
| - |
| 16 | +from _pytest.pytester import LineMatcher |
17 | 17 |
|
18 | 18 | try:
|
19 | 19 | import importlib
|
@@ -776,14 +776,43 @@ def entry():
|
776 | 776 | )
|
777 | 777 | excinfo = pytest.raises(ValueError, mod.entry)
|
778 | 778 |
|
779 |
| - p = FormattedExcinfo() |
| 779 | + p = FormattedExcinfo(abspath=False) |
| 780 | + |
| 781 | + raised = 0 |
| 782 | + |
| 783 | + orig_getcwd = os.getcwd |
780 | 784 |
|
781 | 785 | def raiseos():
|
782 |
| - raise OSError(2) |
| 786 | + nonlocal raised |
| 787 | + if sys._getframe().f_back.f_code.co_name == "checked_call": |
| 788 | + # Only raise with expected calls, but not via e.g. inspect for |
| 789 | + # py38-windows. |
| 790 | + raised += 1 |
| 791 | + raise OSError(2, "custom_oserror") |
| 792 | + return orig_getcwd() |
783 | 793 |
|
784 | 794 | monkeypatch.setattr(os, "getcwd", raiseos)
|
785 | 795 | assert p._makepath(__file__) == __file__
|
786 |
| - p.repr_traceback(excinfo) |
| 796 | + assert raised == 1 |
| 797 | + repr_tb = p.repr_traceback(excinfo) |
| 798 | + |
| 799 | + matcher = LineMatcher(str(repr_tb).splitlines()) |
| 800 | + matcher.fnmatch_lines( |
| 801 | + [ |
| 802 | + "def entry():", |
| 803 | + "> f(0)", |
| 804 | + "", |
| 805 | + "{}:5: ".format(mod.__file__), |
| 806 | + "_ _ *", |
| 807 | + "", |
| 808 | + " def f(x):", |
| 809 | + "> raise ValueError(x)", |
| 810 | + "E ValueError: 0", |
| 811 | + "", |
| 812 | + "{}:3: ValueError".format(mod.__file__), |
| 813 | + ] |
| 814 | + ) |
| 815 | + assert raised == 3 |
787 | 816 |
|
788 | 817 | def test_repr_excinfo_addouterr(self, importasmod, tw_mock):
|
789 | 818 | mod = importasmod(
|
@@ -1201,8 +1230,6 @@ def test_exc_chain_repr_without_traceback(self, importasmod, reason, description
|
1201 | 1230 | real traceback, such as those raised in a subprocess submitted by the multiprocessing
|
1202 | 1231 | module (#1984).
|
1203 | 1232 | """
|
1204 |
| - from _pytest.pytester import LineMatcher |
1205 |
| - |
1206 | 1233 | exc_handling_code = " from e" if reason == "cause" else ""
|
1207 | 1234 | mod = importasmod(
|
1208 | 1235 | """
|
@@ -1321,7 +1348,6 @@ def test_exception_repr_extraction_error_on_recursion():
|
1321 | 1348 | Ensure we can properly detect a recursion error even
|
1322 | 1349 | if some locals raise error on comparison (#2459).
|
1323 | 1350 | """
|
1324 |
| - from _pytest.pytester import LineMatcher |
1325 | 1351 |
|
1326 | 1352 | class numpy_like:
|
1327 | 1353 | def __eq__(self, other):
|
|
0 commit comments