Opened 4 years ago

Closed 4 years ago

#32529 closed Cleanup/optimization (fixed)

Delay creating a test suite inside DiscoverRunner.build_suite()

Reported by: Chris Jerdonek Owned by: Chris Jerdonek
Component: Testing framework Version: 3.1
Severity: Normal Keywords: DiscoverRunner, build_suite, testsuite
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I noticed that DiscoverRunner.build_suite() internally uses a test suite to successively build up its test suite return value. However, build_suite() could be simplified slightly by using a list internally and creating the suite only later towards the end.

One benefit of this is that two of the helper functions that build_suite() calls, namely filter_tests_by_tags() and reorder_suite(), could be updated to operate on simple lists. This would reduce the amount of code that needs to know about test suites and their special handling.

For example, filter_tests_by_tags() could change from this:

def filter_tests_by_tags(suite, tags, exclude_tags):
    suite_class = type(suite)
    return suite_class(
        test for test in iter_test_cases(suite)
        if test_match_tags(test, tags, exclude_tags)
    )

to this:

def filter_tests_by_tags(tests, tags, exclude_tags):
    return [test for test in tests if test_match_tags(test, tags, exclude_tags)]

Change History (5)

comment:1 by Mariusz Felisiak, 4 years ago

Triage Stage: UnreviewedAccepted

comment:2 by Chris Jerdonek, 4 years ago

Owner: changed from nobody to Chris Jerdonek
Status: newassigned

comment:3 by Chris Jerdonek, 4 years ago

Has patch: set
Version 0, edited 4 years ago by Chris Jerdonek (next)

comment:4 by Mariusz Felisiak, 4 years ago

Triage Stage: AcceptedReady for checkin

comment:5 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

Resolution: fixed
Status: assignedclosed

In d828beb6:

Fixed #32529 -- Delayed creating a test suite in build_suite().

Note: See TracTickets for help on using tickets.
Back to Top