-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
typing: fix _TracebackStyle #6482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
from _pytest._code import Source | ||
|
||
_TracebackStyle = Literal["long", "short", "no", "native"] | ||
_TracebackStyle = Literal["long", "short", "line", "no", "native"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"native" in not used internally with FormattedExcinfo
at least (https://github.com/blueyed/pytest/blob/f1609d6e956bdf4d712610d8e6ca9fbb0b2ed108/src/_pytest/_code/code.py#L612-L631), so it might make sense to have two different types here (but it makes sense to match the --tb
option here I guess (currently (with this patch) missing "auto")) - but that would be a followup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should line
be added to ExceptionInfo.getrepr()
docstring?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not think it is used there - i.e. I am not sure.
I think it is only used here:
pytest/src/_pytest/terminal.py
Line 868 in 719e0e3
if self.config.option.tbstyle == "line": |
if call.excinfo.errisinstance(tuple(skip_exceptions)): | ||
outcome = "skipped" | ||
r = collector._repr_failure_py(call.excinfo, "line").reprcrash | ||
r_ = collector._repr_failure_py(call.excinfo, "line") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me, but looking at the type of _repr_failure_py
, I wonder:
- Why do
_repr_failure_py
andrepr_failure
both exist?repr_failure
just forwards directly_repr_failure_py
so why not just inline it? - Is it correct that it can only take
Failed
andFixtureLookupError
and not other exception types? - Is it possible to add overloads to it so this assert is not needed?
- Should its
style
argument be typed with_TracebackStyle
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- it is used by other subclasses etc - it is rather tangled (I have some WIP to fix this, also for 4.)
- IIRC we/I've limited this intentionally for what has been observed, but from the code it is clear that this is not correct:
Lines 288 to 292 in 719e0e3
if isinstance(excinfo.value, Failed): if not excinfo.value.pytrace: return str(excinfo.value) if isinstance(excinfo.value, FixtureLookupError): return excinfo.value.formatrepr() - overload might be a good idea, but in general it would be better to not return a string there. Also it is based on
excinfo.value.pytrace
- so would need separate types for this I assume. - yes, I have that in the WIP to clean up handling of
--fulltrace
from _pytest._code import Source | ||
|
||
_TracebackStyle = Literal["long", "short", "no", "native"] | ||
_TracebackStyle = Literal["long", "short", "line", "no", "native"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should line
be added to ExceptionInfo.getrepr()
docstring?
b74f387
to
09e9a01
Compare
Ref: blueyed#163
TODO: