Ensure logging tests always cleanup after themselves#11531
Merged
nicoddemus merged 2 commits intopytest-dev:mainfrom Oct 23, 2023
Merged
Ensure logging tests always cleanup after themselves#11531nicoddemus merged 2 commits intopytest-dev:mainfrom
nicoddemus merged 2 commits intopytest-dev:mainfrom
Conversation
Member
Author
|
2nd commits adds type annotations for all tests in |
bluetech
approved these changes
Oct 23, 2023
testing/logging/test_fixture.py
Outdated
|
|
||
| # This reaches into private API, don't use this type of thing in real tests! | ||
| assert set(caplog._item.stash[caplog_records_key]) == {"setup", "call"} | ||
| # error: Invalid index type "StashKey[dict[str, list[LogRecord]]]" for "Stash"; |
Member
There was a problem hiding this comment.
I tried playing a bit with the StashKey's TypeVar variance to fix this, but I think it needs to be invariant because it's used in both setters and getters. Maybe the new Python 3.12 type parameter syntax fixes this, didn't check.
Anyway I think it can be worked around by doing it in two lines:
caplog_records = caplog._item.stash[caplog_records_key]
assert set(caplog_records) == {"setup", "call"}
Member
Author
There was a problem hiding this comment.
Indeed that fixes it, however I do not get why... could you explain it, please?
Logging has many global states, and we did foresee this by creating a ``cleanup_disabled_logging`` fixture, however one might still forget to use it and failures leak later -- sometimes not even in the same PR, because the order of the tests might change in the future, specially when running under xdist. This problem surfaced during pytest-dev#11530, where tests unrelated to the change started to fail.
29fe9c4 to
7e69ce7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Logging has many global states, and we did foresee this by creating a
cleanup_disabled_loggingfixture, however one might still forget to use it and failures leak later -- sometimes not even in the same PR, because the order of the tests might change in the future, specially when running under xdist.This problem surfaced during #11530, where tests unrelated to the change started to fail.