Skip to content

Commit d9de53e

Browse files
Capture unraisable error in test
1 parent ae20ab2 commit d9de53e

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/types/iterator.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -405,9 +405,12 @@ def fibonacci(target):
405405
#[cfg(all(feature = "macros", not(Py_LIMITED_API)))]
406406
fn length_hint_error() {
407407
#[crate::pyfunction(crate = "crate")]
408-
fn test_size_hint(obj: &crate::Bound<'_, crate::PyAny>) {
408+
fn test_size_hint(obj: &crate::Bound<'_, crate::PyAny>, should_error: bool) {
409409
let iter = obj.cast::<PyIterator>().unwrap();
410-
assert_eq!((0, None), iter.size_hint());
410+
crate::test_utils::UnraisableCapture::enter(obj.py(), |capture| {
411+
assert_eq!((0, None), iter.size_hint());
412+
assert_eq!(should_error, capture.take_capture().is_some());
413+
});
411414
assert!(PyErr::take(obj.py()).is_none());
412415
}
413416

@@ -431,8 +434,8 @@ def fibonacci(target):
431434
def __length_hint__(self):
432435
raise ValueError("bad hint impl")
433436
434-
test_size_hint(NoHintIter())
435-
test_size_hint(ErrorHintIter())
437+
test_size_hint(NoHintIter(), False)
438+
test_size_hint(ErrorHintIter(), True)
436439
"#
437440
);
438441
});

0 commit comments

Comments
 (0)