Opened 4 years ago

Last modified 4 years ago

#32540 closed Cleanup/optimization

Only do "top level" detection in DiscoverRunner.build_suite() when needed — at Version 1

Reported by: Chris Jerdonek Owned by: nobody
Component: Testing framework Version: dev
Severity: Normal Keywords: DiscoverRunner, build_suite, discovery
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 (last modified by Chris Jerdonek)

Currently, DiscoverRunner.build_suite() is a bit confusing to read because it does "top level" detection for test discovery even when discovery won't be taking place.

My suggestion is to move the top-level detection logic (and large code comment) into a find_top_level(top_level) function that is placed immediately before where is_discoverable() is defined. Then, only call find_top_level() when needed, namely right before where self.test_loader.discover() is called.

Similarly, the kwargs = discover_kwargs.copy() line can also go into that if block right before that line, because that's the only code path where kwargs is actually used. Without this change, it's hard for one to notice that the kwargs are in fact only used for that one line.

Together, this will cut down on the size of build_suite() quite a bit and make it easier to understand.

Change History (1)

comment:1 by Chris Jerdonek, 4 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top