Changes between Initial Version and Version 1 of Ticket #32489, comment 5


Ignore:
Timestamp:
Feb 28, 2021, 6:19:02 PM (4 years ago)
Author:
Chris Jerdonek

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #32489, comment 5

    initial v1  
    11Also, I just noticed that the proposed `iter_test_cases()` should probably also sport a `reverse` keyword argument, to support e.g. `partition_suite_by_type()`. That way `partition_suite_by_type()` won't need to construct the full list before reversing it.
    22
    3 (I can update my code snippet above to support passing `reverse`.)
     3The new implementation of `iter_test_cases()` (following the pattern of `partition_suite_by_type()`) would be:
     4
     5{{{#!python
     6def 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}}}
Back to Top