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
[https://github.com/django/django/blob/551b0f94bf62c81d9ff9d5f7e261bcd2a594a4d1/django/test/runner.py#L603
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/32540>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Old description:
> Currently, `DiscoverRunner.build_suite()` is a bit confusing to read
> because it does
> [https://github.com/django/django/blob/551b0f94bf62c81d9ff9d5f7e261bcd2a594a4d1/django/test/runner.py#L577-L599
> "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
> [https://github.com/django/django/blob/551b0f94bf62c81d9ff9d5f7e261bcd2a594a4d1/django/test/runner.py#L603
> 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.
New description:
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
[https://github.com/django/django/blob/551b0f94bf62c81d9ff9d5f7e261bcd2a594a4d1/django/test/runner.py#L603
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.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/32540#comment:1>
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/32540#comment:2>
* owner: nobody => Chris Jerdonek
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/32540#comment:3>
* has_patch: 0 => 1
Comment:
PR: https://github.com/django/django/pull/14120
--
Ticket URL: <https://code.djangoproject.com/ticket/32540#comment:4>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/32540#comment:5>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"d5a214c7c4575773e0f1b8b99f6018bcb7adb8cd" d5a214c7]:
{{{
#!CommitTicketReference repository=""
revision="d5a214c7c4575773e0f1b8b99f6018bcb7adb8cd"
Refs #32540 -- Added django.test.runner.find_top_level().
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32540#comment:6>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"7bdd09d016f418719f2d0297f58bd81c5349101d" 7bdd09d]:
{{{
#!CommitTicketReference repository=""
revision="7bdd09d016f418719f2d0297f58bd81c5349101d"
Fixed #32540 -- Optimized DiscoverRunner.build_suite() by calling
find_top_level() only if is_discoverable() is true.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32540#comment:7>