3 | | (I can update my code snippet above to support passing `reverse`.) |
| 3 | The new implementation of `iter_test_cases()` (following the pattern of `partition_suite_by_type()`) would be: |
| 4 | |
| 5 | {{{#!python |
| 6 | def iter_test_cases(suite, reverse=False): |
| 7 | """Return an iterator over a test suite's unittest.TestCase objects.""" |
| 8 | # Django permits custom TestSuite classes, so use the caller's class. |
| 9 | suite_class = type(suite) |
| 10 | if reverse: |
| 11 | suite = reversed(tuple(suite)) |
| 12 | for test in suite: |
| 13 | if isinstance(test, suite_class): |
| 14 | yield from iter_test_cases(suite, reverse=reverse) |
| 15 | else: |
| 16 | yield test |
| 17 | }}} |