-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[py] Reduce traceback output on test failures #16854
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
[py] Reduce traceback output on test failures #16854
Conversation
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
||||||||||||||||||||||||
PR Code Suggestions ✨Explore these optional code suggestions:
|
||||||||||||||||||||
navin772
left a comment
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.
LGTM!
User description
🔗 Related Issues
Fixes #16850
💥 What does this PR do?
This PR changes how tracebacks are displayed on test failures when running the Python test suite (locally/RBE/GHA). Previously, we were displaying hundreds of lines of source code and traceback frames on failures.
To fix this, this PR replaces pytest's traceback display with the
rich.tracebackmodule: https://rich.readthedocs.io/en/latest/traceback.htmlThis allows finer grained control and better formatting than pytest's built-in functionality.
What this does:
DeprecationWarningfrom outputExample output:
unit test failure on GHA:
https://github.com/SeleniumHQ/selenium/actions/runs/20736146980/job/59534158251?pr=16854#step:20:441
integration test failure on GHA:
https://github.com/SeleniumHQ/selenium/actions/runs/20736146980/job/59534158276?pr=16854#step:20:4315
integration test failure on RBE:
https://gypsum.cluster.engflow.com/invocations/default/c1c859d6-84a4-4c81-8f1d-3c2849e24803
💡 Additional Considerations
By replacing pytest's traceback handling, we are losing the traceback introspection from standard pytest asserts. However, introspection is only done when a custom assertion message isn't displayed, and we usually add them. I think this is a reasonable trade-off to reduce noise in output.
🔄 Types of changes
PR Type
Enhancement, Tests
Description
Replaces pytest's traceback display with rich.traceback module
Filters out pytest internals and frames without source files
Limits traceback frames to maximum of 5 for clarity
Disables ANSI colors on RBE to prevent log file corruption
Ignores DeprecationWarning messages in test output
Diagram Walkthrough
File Walkthrough
conftest.py
Add rich traceback formatting with pytest hookpy/conftest.py
types,rich.console, andrich.tracebackmodulesextract_traceback_frames()to extract frames from tracebackobjects
filter_frames()to remove pytest internal framesrebuild_traceback()to reconstruct traceback from filteredframes
pytest_runtest_makereport()hook to intercept testfailures and display rich-formatted tracebacks with max 5 frames
environment detection
BUILD.bazel
Add rich dependency for testspy/BUILD.bazel
richpackage to TEST_DEPS requirement listpyproject.toml
Configure pytest to suppress default tracebackspy/pyproject.toml
--tb=no)and enable output capture suppression (
-s)