Skip to content

gh-106368: Argument clinic tests: improve failure message when tests in ClinicExternalTests fail - #107364

Merged
AlexWaygood merged 2 commits into
python:mainfrom
AlexWaygood:clinic-test-message
Jul 27, 2023
Merged

gh-106368: Argument clinic tests: improve failure message when tests in ClinicExternalTests fail#107364
AlexWaygood merged 2 commits into
python:mainfrom
AlexWaygood:clinic-test-message

Conversation

@AlexWaygood

@AlexWaygoodAlexWaygood commented Jul 27, 2023

Copy link
Copy Markdown
Member

Currently, if I apply this diff to Tools/clinic/clinic.py...

--- a/Tools/clinic/clinic.py+++ b/Tools/clinic/clinic.py@@ -4702,6 +4702,7 @@ def state_modulename_name(self, line: str | None) -> None:
fields = [x.strip() for x in existing.split('.')]
function_name = fields.pop()
module, cls = self.clinic._module_and_class(fields)
+ 1/0
for existing_function in (cls or module).functions:
if existing_function.name == function_name:

...then the argument clinic tests fail for me locally (good!), but the failure message is terrible (bad!):

======================================================================
FAIL: test_external (test.test_clinic.ClinicExternalTest.test_external)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\alexw\coding\cpython\Lib\test\test_clinic.py", line 1410, in test_external
out =self.expect_success("-f", "-o", TESTFN, source)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\alexw\coding\cpython\Lib\test\test_clinic.py", line 1397, in expect_successreturnself._do_test(*args)
^^^^^^^^^^^^^^^^^^^^
File "C:\Users\alexw\coding\cpython\Lib\test\test_clinic.py", line 1389, in _do_testself.fail("".join(proc.stderr))
AssertionError
----------------------------------------------------------------------

This change makes the error message much more helpful!

======================================================================
FAIL: test_external (test.test_clinic.ClinicExternalTest.test_external)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\alexw\coding\cpython\Lib\test\test_clinic.py", line 1411, in test_external
out =self.expect_success("-f", "-o", TESTFN, source)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\alexw\coding\cpython\Lib\test\test_clinic.py", line 1398, in expect_successreturnself._do_test(*args)
^^^^^^^^^^^^^^^^^^^^
File "C:\Users\alexw\coding\cpython\Lib\test\test_clinic.py", line 1390, in _do_testself.fail("".join(itertools.chain(proc.stdout, proc.stderr)))
AssertionError: Error in file "C:\Users\alexw\coding\cpython\Lib\test\clinic.test.c" on line 117:
Exception raised during parsing:
Traceback (most recent call last):
File "C:\Users\alexw\coding\cpython\Tools\clinic\clinic.py", line 2244, in parse
parser.parse(block)
File "C:\Users\alexw\coding\cpython\Tools\clinic\clinic.py", line 4608, in parseself.state(line)
File "C:\Users\alexw\coding\cpython\Tools\clinic\clinic.py", line 4666, in state_dsl_startself.next(self.state_modulename_name, line)
File "C:\Users\alexw\coding\cpython\Tools\clinic\clinic.py", line 4648, in nextself.state(line)
File "C:\Users\alexw\coding\cpython\Tools\clinic\clinic.py", line 4705, in state_modulename_name1/0~^~ZeroDivisionError: division by zero
----------------------------------------------------------------------

(@erlend-aasland do you see the same thing locally? Am I seeing something different because I'm using a Windows box?)

@bedevere-botbedevere-bot added awaiting core review tests Tests in the Lib/test dir labels Jul 27, 2023
@AlexWaygoodAlexWaygood changed the title Argument clinic tests: improve failure message when tests in ClinicExternalTests failgh-106368: Argument clinic tests: improve failure message when tests in ClinicExternalTests failJul 27, 2023
Comment threadLib/test/test_clinic.py Outdated
Comment threadLib/test/test_clinic.py Outdated

@erlend-aaslanderlend-aasland left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! (BTW, I love itertools!)

@miss-islington

Copy link
Copy Markdown
Contributor

Thanks @AlexWaygood for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11, 3.12.
🐍🍒⛏🤖

@bedevere-bot

Copy link
Copy Markdown

GH-107365 is a backport of this pull request to the 3.12 branch.

@bedevere-botbedevere-bot removed the needs backport to 3.12 only security fixes label Jul 27, 2023
@bedevere-bot

Copy link
Copy Markdown

GH-107366 is a backport of this pull request to the 3.11 branch.

@bedevere-botbedevere-bot removed the needs backport to 3.11 only security fixes label Jul 27, 2023
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 27, 2023
…tests in `ClinicExternalTests` fail (pythonGH-107364)
(cherry picked from commit 76c26ea)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 27, 2023
…tests in `ClinicExternalTests` fail (pythonGH-107364)
(cherry picked from commit 76c26ea)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
@AlexWaygood
AlexWaygood deleted the clinic-test-message branch July 27, 2023 23:58
AlexWaygood added a commit that referenced this pull request Jul 28, 2023
… tests in `ClinicExternalTests` fail (GH-107364) (#107366)
gh-106368: Argument clinic tests: improve failure message when tests in `ClinicExternalTests` fail (GH-107364)
(cherry picked from commit 76c26ea)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
AlexWaygood added a commit that referenced this pull request Jul 28, 2023
… tests in `ClinicExternalTests` fail (GH-107364) (#107365)
gh-106368: Argument clinic tests: improve failure message when tests in `ClinicExternalTests` fail (GH-107364)
(cherry picked from commit 76c26ea)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip newstestsTests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@AlexWaygood@miss-islington@bedevere-bot@erlend-aasland