redact line numbers from grouped exception message (#33485)

This commit is contained in:
Danny McClanahan 2022-10-24 13:08:18 -04:00 committed by GitHub
parent a51bd80a5e
commit 0b971a1aef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,6 +4,7 @@
# SPDX-License-Identifier: (Apache-2.0 OR MIT) # SPDX-License-Identifier: (Apache-2.0 OR MIT)
import os.path import os.path
import re
import sys import sys
from datetime import datetime, timedelta from datetime import datetime, timedelta
from textwrap import dedent from textwrap import dedent
@ -307,22 +308,25 @@ def inner():
top-level raised TypeError: ok""" top-level raised TypeError: ok"""
) )
full_message = h.grouped_message(with_tracebacks=True)
no_line_numbers = re.sub(r"line [0-9]+,", "line xxx,", full_message)
assert ( assert (
h.grouped_message(with_tracebacks=True) no_line_numbers
== dedent( == dedent(
"""\ """\
due to the following failures: due to the following failures:
inner method raised ValueError: wow! inner method raised ValueError: wow!
File "{0}", \ File "{0}", \
line 298, in test_grouped_exception line xxx, in test_grouped_exception
inner() inner()
File "{0}", \ File "{0}", \
line 295, in inner line xxx, in inner
raise ValueError("wow!") raise ValueError("wow!")
top-level raised TypeError: ok top-level raised TypeError: ok
File "{0}", \ File "{0}", \
line 301, in test_grouped_exception line xxx, in test_grouped_exception
raise TypeError("ok") raise TypeError("ok")
""" """
).format(__file__) ).format(__file__)