Skip to content

Commit 4dd05c0

Browse files
authored
Add TypeError for bare @requires_crt usage and regression tests (#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
1 parent bbb6100 commit 4dd05c0

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

tests/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ def tearDown(self):
5252

5353

5454
def requires_crt(reason=None):
55+
if callable(reason):
56+
raise TypeError(
57+
"Use @requires_crt() with parentheses, not bare @requires_crt"
58+
)
5559
if reason is None:
5660
reason = "Test requires awscrt to be installed"
5761

tests/unit/test_crt.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,30 @@ def test_config_without_crt_support_emits_warning(
231231
for r in caplog.records
232232
]
233233
)
234+
235+
236+
class TestRequiresCrt:
237+
def test_bare_requires_crt_fails_immediately(self):
238+
with pytest.raises(TypeError):
239+
240+
@requires_crt
241+
def my_test():
242+
pass
243+
244+
def test_requires_crt_skips_when_no_crt(self):
245+
with mock.patch('tests.HAS_CRT', False):
246+
247+
@requires_crt()
248+
def my_test():
249+
assert False
250+
251+
assert getattr(my_test, '__unittest_skip__', False) is True
252+
253+
def test_requires_crt_runs_when_crt_available(self):
254+
with mock.patch('tests.HAS_CRT', True):
255+
256+
@requires_crt()
257+
def my_test():
258+
pass
259+
260+
assert getattr(my_test, '__unittest_skip__', False) is False

0 commit comments

Comments
 (0)