Skip to content

Conversation

ydshieh
Copy link
Collaborator

@ydshieh ydshieh commented Sep 17, 2025

What does this PR do?


# The frame that calls this patched method (it may not be the test method)
# -1: `_get_test_info`; -2: `patched_xxx`; -3: the caller to `patched_xxx`
caller_frame = stack[-3]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was a bit hardcoded, and it turns out that this causes issue when @require_read_token is applied to a test class, where we will get

stack[-1]: _get_test_info
stack[-2]: patched
stack[-3]: wrapper (from def require_read_token)
stack[-4]: the caller to the method that is wrapped (in this case, it's self.assertEqual)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Example is

FAILED tests/models/mistral/test_modeling_mistral.py::MistralIntegrationTest::test_speculative_generation - TypeError: 'NoneType' object is not subscriptable

where we have

@require_read_token
class MistralIntegrationTest(unittest.TestCase):

Comment on lines +3499 to +3500
if origin_method_being_patched.__name__ in frame.line:
caller_frame = frame
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In this PR, we check against the name of the original method being patched.

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@ydshieh ydshieh merged commit 89949c5 into main Sep 17, 2025
22 of 24 checks passed
@ydshieh ydshieh deleted the fix_patched branch September 17, 2025 09:42
ErfanBaghaei pushed a commit to ErfanBaghaei/transformers that referenced this pull request Sep 25, 2025
* fix

* fix

---------

Co-authored-by: ydshieh <ydshieh@users.noreply.github.com>
vijayabhaskar-ev pushed a commit to vijayabhaskar-ev/transformers that referenced this pull request Oct 2, 2025
* fix

* fix

---------

Co-authored-by: ydshieh <ydshieh@users.noreply.github.com>
yuchenxie4645 pushed a commit to yuchenxie4645/transformers that referenced this pull request Oct 4, 2025
* fix

* fix

---------

Co-authored-by: ydshieh <ydshieh@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants