-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
Terrible user experience if test_exceptions.ExceptionTests.test_recursion_normalizing_infinite_exception
fails
#117606
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
Comments
Would this be acceptable? It will tell you -self.assertIn(b'RecursionError: maximum recursion depth exceeded', err)
+# gh-117606: Don't use assertIn! The error message can be really long.
+self.assertTrue(b'RecursionError: maximum recursion depth exceeded' in err) Example output: import unittest
class MyTestCase(unittest.TestCase):
def test(self):
err = "good"
self.assertTrue("bad" in err)
unittest.main()
|
What about something like this, so that you can still see the traceback that you actually got, but it's truncated so that it can reasonably fit on your screen? diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py
index 36fd89dbb8..000337d08f 100644
--- a/Lib/test/test_exceptions.py
+++ b/Lib/test/test_exceptions.py
@@ -1451,7 +1451,8 @@ def test_recursion_normalizing_infinite_exception(self):
"""
rc, out, err = script_helper.assert_python_failure("-c", code)
self.assertEqual(rc, 1)
- self.assertIn(b'RecursionError: maximum recursion depth exceeded', err)
+ expected = b'RecursionError: maximum recursion depth exceeded'
+ self.assertTrue(expected in err, msg=f"{expected} not found in {err[:3_000]!r}... (truncated)")
self.assertIn(b'Done.', out)
Output:
|
Yeah, that would be even better, and it doesn't need a comment to explain the use of |
Feel free to make a PR! :-) |
…#117670) Co-authored-by: Alex Waygood <[email protected]>
…tions` (pythonGH-117670) (cherry picked from commit 02f1385) Co-authored-by: Nice Zombies <[email protected]> Co-authored-by: Alex Waygood <[email protected]>
…ptions` (GH-117670) (#117745) gh-117606: Truncate extremely long error message in `test_exceptions` (GH-117670) (cherry picked from commit 02f1385) Co-authored-by: Nice Zombies <[email protected]> Co-authored-by: Alex Waygood <[email protected]>
…tions` (python#117670) Co-authored-by: Alex Waygood <[email protected]>
Bug report
Bug description:
If
test_exceptions.ExceptionTests.test_recursion_normalizing_infinite_exception
fails, a huge amount of output is printed to the terminal, which is a pretty terrible user experience. The full output is here: exception_tb.txt.To reproduce, run
FORCE_COLOR ./python.exe -m unittest -v test.test_exceptions.ExceptionTests.test_recursion_normalizing_infinite_exception
.(Note that this issue isn't about the test failing when
FORCE_COLOR
is set. #117605 is about that. This issue is about the poor user experience if the test fails.)CPython versions tested on:
CPython main branch
Operating systems tested on:
macOS
Linked PRs
test_exceptions
#117670test_exceptions
(GH-117670) #117745The text was updated successfully, but these errors were encountered: