-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
gh-109485: Further improve test_future_stmt
tests
#109486
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
Conversation
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.
Would it be possible to check for the error message in assertSyntaxError?
|
||
def test_badfuture10(self): | ||
def test_bad_future_as_module(self): |
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.
Test name is not clear. The expected error is:
SyntaxError: from __future__ imports must occur at the beginning of the file
With error messages it should be much better! |
lineno, | ||
message=TOP_LEVEL_MSG, offset=1, | ||
parametrize_docstring=True): | ||
code = dedent(code) |
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.
It seems like code first line is always empty. I suggest using:
code = dedent(code) | |
code = dedent(code.lstrip()) |
And adapt lineno -= 2
and other references to lineno below.
For example, for me, test_unknown_future_flag() code has only 3 lines and expect an error on the 4th line, it's strange.
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. Thanks! It's way way more readable now! The test methods have better name, it's easier to understand the purpose of the test, and you added many checks!
code = dedent(code.lstrip('\n')) | ||
for trim_docstring in ([False, True] if parametrize_docstring else [False]): | ||
with self.subTest(code=code, trim_docstring=trim_docstring): | ||
if trim_docstring: |
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.
Last question: instead of copy/paste '''Docstring'''
in each test. Would it make sense to add it here instead? I'm waiting for your opinion to decide if we merge the change like that, or you prefer to remove docstrings in tests and add it here instead.
Thanks a lot @sobolevn, it's way better! I edited the final message. |
I've also enabled docstring parametrization, because tests must works the same way with and without docstrings most of the time.
test_future_stmt
#109485