From 408de2298cefb9c4c35e45e27c050e11f7d2b5e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Thu, 7 Oct 2021 13:17:59 +0200 Subject: [PATCH] bpo-45400: Fix test_name_error_suggestions_do_not_trigger_for_too_many_locals on a1 releases When test_name_error_suggestions_do_not_trigger_for_too_many_locals run from a directory that contained "a1" somewhere in the path, which was likely to happen when building from unpacked sources of a first alpha release, it failed, as it asserts the string "a1" is nowhere in the traceback. Now, we replace the full path in the traceback with basename to prevent this. --- Lib/test/test_exceptions.py | 8 +++++++- .../next/Tests/2021-10-07-13-17-42.bpo-45400.oHgprZ.rst | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Tests/2021-10-07-13-17-42.bpo-45400.oHgprZ.rst diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py index 289288478c285ae..075b1c41ff3d7f9 100644 --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -1840,7 +1840,13 @@ def f(): with support.captured_stderr() as err: sys.__excepthook__(*sys.exc_info()) - self.assertNotIn("a1", err.getvalue()) + traceback = err.getvalue() + + # remvoe the source path from the traceback, it could contain "a1" in it + # https://bugs.python.org/issue45400 + traceback = traceback.replace(__file__, os.path.basename(__file__)) + + self.assertNotIn("a1", traceback) def test_name_error_with_custom_exceptions(self): def f(): diff --git a/Misc/NEWS.d/next/Tests/2021-10-07-13-17-42.bpo-45400.oHgprZ.rst b/Misc/NEWS.d/next/Tests/2021-10-07-13-17-42.bpo-45400.oHgprZ.rst new file mode 100644 index 000000000000000..ac586d7a0050ac0 --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2021-10-07-13-17-42.bpo-45400.oHgprZ.rst @@ -0,0 +1,4 @@ +The ``test_name_error_suggestions_do_not_trigger_for_too_many_locals`` will +no longer fail when run from a directory that contains ``a1`` in the path, +which is likely to happen when building from unpacked sources of a first +alpha release.