Opened 4 years ago

Closed 4 years ago

#32540 closed Cleanup/optimization (fixed)

Only do "top level" detection in DiscoverRunner.build_suite() when needed

Reported by: Chris Jerdonek Owned by: Chris Jerdonek
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 (7)

comment:1 by Chris Jerdonek, 4 years ago

Description: modified (diff)

comment:2 by Mariusz Felisiak, 4 years ago

Triage Stage: UnreviewedAccepted

comment:3 by Chris Jerdonek, 4 years ago

Owner: changed from nobody to Chris Jerdonek
Status: newassigned

comment:5 by Mariusz Felisiak, 4 years ago

Triage Stage: AcceptedReady for checkin

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

In d5a214c7:

Refs #32540 -- Added django.test.runner.find_top_level().

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

Resolution: fixed
Status: assignedclosed

In 7bdd09d:

Fixed #32540 -- Optimized DiscoverRunner.build_suite() by calling find_top_level() only if is_discoverable() is true.

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