Merge pull request #7708 from nicoddemus/repr-line-7707
Fix handle of exceptions in ReprEntry with tb=line
This commit is contained in:
@@ -4,6 +4,8 @@ import os
|
||||
import queue
|
||||
import sys
|
||||
import textwrap
|
||||
from typing import Any
|
||||
from typing import Dict
|
||||
from typing import Tuple
|
||||
from typing import Union
|
||||
|
||||
@@ -1045,28 +1047,34 @@ raise ValueError()
|
||||
@pytest.mark.parametrize(
|
||||
"reproptions",
|
||||
[
|
||||
{
|
||||
"style": style,
|
||||
"showlocals": showlocals,
|
||||
"funcargs": funcargs,
|
||||
"tbfilter": tbfilter,
|
||||
}
|
||||
for style in ("long", "short", "no")
|
||||
pytest.param(
|
||||
{
|
||||
"style": style,
|
||||
"showlocals": showlocals,
|
||||
"funcargs": funcargs,
|
||||
"tbfilter": tbfilter,
|
||||
},
|
||||
id="style={},showlocals={},funcargs={},tbfilter={}".format(
|
||||
style, showlocals, funcargs, tbfilter
|
||||
),
|
||||
)
|
||||
for style in ["long", "short", "line", "no", "native", "value", "auto"]
|
||||
for showlocals in (True, False)
|
||||
for tbfilter in (True, False)
|
||||
for funcargs in (True, False)
|
||||
],
|
||||
)
|
||||
def test_format_excinfo(self, importasmod, reproptions):
|
||||
mod = importasmod(
|
||||
"""
|
||||
def g(x):
|
||||
raise ValueError(x)
|
||||
def f():
|
||||
g(3)
|
||||
"""
|
||||
)
|
||||
excinfo = pytest.raises(ValueError, mod.f)
|
||||
def test_format_excinfo(self, reproptions: Dict[str, Any]) -> None:
|
||||
def bar():
|
||||
assert False, "some error"
|
||||
|
||||
def foo():
|
||||
bar()
|
||||
|
||||
# using inline functions as opposed to importasmod so we get source code lines
|
||||
# in the tracebacks (otherwise getinspect doesn't find the source code).
|
||||
with pytest.raises(AssertionError) as excinfo:
|
||||
foo()
|
||||
file = io.StringIO()
|
||||
tw = TerminalWriter(file=file)
|
||||
repr = excinfo.getrepr(**reproptions)
|
||||
|
||||
Reference in New Issue
Block a user