Treat malformed unittest skips as collection errors#14732
Closed
zhangli091011 wants to merge 2 commits into
Closed
Treat malformed unittest skips as collection errors#14732zhangli091011 wants to merge 2 commits into
zhangli091011 wants to merge 2 commits into
Conversation
Preserve deliberate unittest.SkipTest module skips while reporting SkipTest raised by unittest's generated skip decorator wrapper as an import-time collection error. Co-authored-by: OpenCode <opencode@users.noreply.github.com>
Twisted replaces unittest.case.SkipTest during its integration tests, while preserving the collection-error behavior under test. Co-authored-by: OpenCode <opencode@users.noreply.github.com>
Member
This... doesn't exactly convince me that this actually happened? |
This comment was marked as low quality.
This comment was marked as low quality.
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.
Closes #10821.
Summary
Malformed use of an aliased
unittest.skipdecorator currently raisesunittest.SkipTestfrom unittest's generatedskip_wrapperwhile importing the test module. Pytest classifies every collection-timeunittest.SkipTestas a module skip, so this programming error can hide all tests in that module.This keeps legitimate unittest module skipping intact and changes only
SkipTestwhose innermost traceback frame is unittest's generatedskip_wrapper. Such exceptions are now normal collection errors. Direct module-levelraise unittest.SkipTest(...)remains a skipped module, matchingunittest.TestLoader.discover, andpytest.skip(..., allow_module_level=True)is unaffected.This narrower boundary addresses the compatibility concern raised on #10864 and #14415 rather than removing collection-time
SkipTesthandling wholesale.Tests
python -m pytest testing/test_unittest.py testing/test_runner.py testing/test_skipping.py(231 passed, 9 skipped, 1 xfailed)tox -e py310 -- testing/test_unittest.py -k "raising_unittest_skiptest_during_collection or unittest_skip_decorator_misuse_is_collection_error"(2 passed)python -m pytest testing/test_unittest.py -k "raising_unittest_skiptest_during_collection or unittest_skip_decorator_misuse_is_collection_error"on Python 3.13 (2 passed)pre-commit run --all-files --show-diff-on-failure(passed, including Ruff, formatting, mypy, RST and policy hooks)Current
mainwas reproduced separately: the issue example reportscollected 0 items / 1 skippedbefore this change.AI assistance
OpenCode assisted with repository inspection, implementation, and validation, and is credited by a
Co-authored-bytrailer. I reviewed the complete diff and tests, understand the traceback-based compatibility boundary, and take responsibility for this change and reviewer follow-up in accordance with pytest's AI/LLM-Assisted Contributions Policy.AUTHORS.