-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
apply warnings filter as soon as possible, and remove it as late as possible #13057
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
…o gc.collect() is called with the warning filters in place
@@ -1112,9 +1112,7 @@ def add_cleanup(self, func: Callable[[], None]) -> None: | |||
def _do_configure(self) -> None: | |||
assert not self._configured | |||
self._configured = True | |||
with warnings.catch_warnings(): |
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.
not sure what this was for - it just disables the user specified warning filter during config. We don't want this.
for more information, see https://pre-commit.ci
Wait, Would be nice with a test for Can perhaps also add a test that hits |
No, test_create_task_unraisable relies on the warning filter set by the host test suite
I make my own object that behaves like an unawaited coro, I don't think it's needed
CI absolutely covers this case - without it CI fails. I suspect coverage isn't running on the lsof tests |
The only line that differs is whether you do
It might just be me, but skimming at #10404 + the test I need to spend a minute to figure out how the test functions as a regression test for it. So IMO at least a comment, but would personally have a test that is more obviously equivalent to the issue.
in this case it's not GitHub annotations lying, you don't have 100% patch coverage |
This shouldn't be the case, the filterwarnings mark is also different - it disables the host pytest warning filter
Ok, I suppose it does makes sense to do a more obvious regression test
Yeah, what I mean to say is that CI fails without this change because the warning previously was issued too late and so wouldn't trigger an error. Now that it's correctly raised as an error CI fails unless I explicitly ignore it, hence giving it a new type |
Uh, sorry for not doing a threaded convo as a review. Don't ask me why I didn't.
Ah, derp. I guess a comment or two explaining how they differ would help other people as blind as me.
right, yeah. Weird it doesn't show up as being covered then. Maybe only hit in a subprocess pytester invokation? If so we can perhaps add a more explicit test case for it |
@jakkdl ok I've pushed a new test and some comments |
@jakkdl also enabling coverage on lsof tests seems to fix the missing coverage |
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 be nice if one test (or a separate test) doesn't run with -Werror
, but otherwise looks great.
with _disable_gc(): | ||
result = pytester.runpytest("-Werror") | ||
|
||
# TODO: should be a test failure or error | ||
assert result.ret == pytest.ExitCode.INTERNAL_ERROR | ||
|
||
result.assert_outcomes(passed=1) | ||
result.stderr.fnmatch_lines("RuntimeWarning: coroutine 'my_task' was never awaited") |
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.
If we run this without -Werror
we can check that normal warning functionality works.
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.
ah I broke it! Very good catch! I'll send a commit to fix it now
with warnings.catch_warnings(record=True) as log: | ||
# mypy can't infer that record=True means log is not None; help it. | ||
assert log is not None | ||
|
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.
Looking at typeshed I think the comment was previously incorrect and the assert wasn't needed https://github.com/python/typeshed/blob/54e1c6ad58961c1faebc6842698eec78f1298f92/stdlib/warnings.pyi#L82
But ye with current logic mypy can't infer if record -> log is not None
later in the func
closes #10404