Skip to content

Add TypeError for bare @requires_crt usage and regression tests#4734

Merged
jonathan343 merged 2 commits intoboto:developfrom
Alan4506:requires_crt_fix
Mar 11, 2026
Merged

Add TypeError for bare @requires_crt usage and regression tests#4734
jonathan343 merged 2 commits intoboto:developfrom
Alan4506:requires_crt_fix

Conversation

@Alan4506
Copy link
Copy Markdown
Contributor

@Alan4506 Alan4506 commented Mar 11, 2026

Background:
@requires_crt is used to skip tests when the optional CRT dependency is not installed. The only supported form should be @requires_crt(). Using bare @requires_crt is unsafe because requires_crt is implemented as a decorator factory. Python passes the test function as the reason argument, causing the real test body to never run. Assertions are never evaluated, but the test may still appear to pass or skip silently.

Description of changes:
This PR makes bare @requires_crt fail immediately with a TypeError. All existing usages in boto3 already use @requires_crt() with parentheses.

Testing:
Regression tests are added to verify correct behavior. All tests including the new tests pass.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Copy link
Copy Markdown
Contributor

@jonathan343 jonathan343 left a comment

Choose a reason for hiding this comment

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

Left a very minor nit. Looks good to me though!

You may want to add something brief in your description for why we're adding this change.

Comment thread tests/unit/test_crt.py Outdated
def my_test():
pass

assert not getattr(my_test, '__unittest_skip__', False)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit - Minor style preference to be consistent with the is True above

Suggested change
assert not getattr(my_test, '__unittest_skip__', False)
assert getattr(my_test, '__unittest_skip__', False) is False

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Both description and code updated. Thanks for the suggestion!

@jonathan343 jonathan343 merged commit 4dd05c0 into boto:develop Mar 11, 2026
45 checks passed
aws-sdk-python-automation added a commit that referenced this pull request Mar 11, 2026
* release-1.42.66:
  Bumping version to 1.42.66
  Add changelog entries from botocore
  Add TypeError for bare @requires_crt usage and regression tests (#4734)
  Update documentation.yml (#4725)
hswong3i pushed a commit to alvistack/boto-boto3 that referenced this pull request Mar 12, 2026
…#4734)

* Add TypeError for bare @requires_crt usage and regression tests

* use `is False` for consistency with `is True` assertion in requires_crt regression tests
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.

2 participants