Changes between Initial Version and Version 1 of Ticket #32668
- Timestamp:
- Apr 20, 2021, 6:43:31 PM (4 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #32668 – Description
initial v1 1 This is another clean-up follow-up to [https://github.com/django/django/pull/4106 PR #4106], similar to ([https://github.com/django/django/pull/14276 PR #14276].1 This is another clean-up follow-up to [https://github.com/django/django/pull/4106 PR #4106], similar to [https://github.com/django/django/pull/14276 PR #14276]. 2 2 3 TLDR: Refactor out from `runtests.py`'s [https://github.com/django/django/blob/54e94640ace261b14cf8cdb1fae3dc6f068a5f87/tests/runtests.py#L135 setup()] and [https://github.com/django/django/blob/54e94640ace261b14cf8cdb1fae3dc6f068a5f87/tests/runtests.py#L263 teardown()] simpler `setup_test_collection()` and `teardown_test_collection()` functions for use in the new [https://github.com/django/django/blob/54e94640ace261b14cf8cdb1fae3dc6f068a5f87/tests/runtests.py#L337-L342 get_app_test_labels()] (used for `bisect_tests()` and `paired_tests()`). (The exact names aren't so important.)3 TLDR: Refactor out from `runtests.py`'s 125-line [https://github.com/django/django/blob/54e94640ace261b14cf8cdb1fae3dc6f068a5f87/tests/runtests.py#L135 setup()] and [https://github.com/django/django/blob/54e94640ace261b14cf8cdb1fae3dc6f068a5f87/tests/runtests.py#L263 teardown()] simpler `setup_test_collection()` and `teardown_test_collection()` functions for use in the new [https://github.com/django/django/blob/54e94640ace261b14cf8cdb1fae3dc6f068a5f87/tests/runtests.py#L337-L342 get_app_test_labels()] (used for `bisect_tests()` and `paired_tests()`). (The exact names aren't so important.) 4 4 5 5 Longer version: … … 7 7 Currently, `runtests.py`'s `setup()` function and its role in getting the list of default test labels for `bisect_tests()`, `paired_tests()`, and [https://github.com/django/django/blob/413c15ef2e3d3958fb641a023bc1e2d15fb2b228/tests/runtests.py#L332 test_runner.run_tests()] is a bit complicated and harder to understand than it needs to be. 8 8 9 There are a couple reasons for this. First, `setup()` is actually doing two kinds of setup: one for collecting the default test labels (always needed), and one for setting up the test run (needed only for [https://github.com/django/django/blob/54e94640ace261b14cf8cdb1fae3dc6f068a5f87/tests/runtests.py#L301 django_tests()] but not`bisect_tests()` and `paired_tests()`). Second, the way the list of default test labels is obtained is a bit roundabout. Namely, a bunch of apps are added to `INSTALLED_APPS`, and then `runtests.py`'s `get_installed()` is called to read from `INSTALLED_APPS`. However, for test-collection, `INSTALLED_APPS` doesn't actually need to be modified. You can see a side effect of this in the fact that `get_installed()` doesn't just return test labels. It also returns the following modules, which no longer contain any tests (this is the thing that [https://github.com/django/django/pull/4106 PR #4106] from six years ago fixed):9 There are a couple reasons for this. First, `setup()` is actually doing two kinds of setup: one for collecting the default test labels, and one for setting up the test run (needed only for [https://github.com/django/django/blob/54e94640ace261b14cf8cdb1fae3dc6f068a5f87/tests/runtests.py#L301 django_tests()] but never `bisect_tests()` and `paired_tests()`). Second, the way the list of default test labels is obtained is a bit roundabout. Namely, a bunch of apps are added to `INSTALLED_APPS`, and then `runtests.py`'s `get_installed()` is called to read from `INSTALLED_APPS`. However, for test-collection, `INSTALLED_APPS` doesn't actually need to be modified. You can see a side effect of this in the fact that `get_installed()` doesn't just return test labels. It also returns the following modules, which no longer contain any tests (this is the thing that [https://github.com/django/django/pull/4106 PR #4106] from six years ago fixed): 10 10 `django.contrib.admin`, `django.contrib.auth`, `django.contrib.contenttypes`, `django.contrib.flatpages`, `django.contrib.messages`, `django.contrib.redirects`, `django.contrib.sessions`, `django.contrib.sites`, `django.contrib.staticfiles`. 11 11 12 By extracting out from `setup()` a `setup_test_collection()` function that just collects and returns the t est labels, I think things will become a lot easier to understand and work with -- not just for `bisect_tests()` and `paired_tests()`, but also for the main `django_tests()` case.12 By extracting out from `setup()` a `setup_test_collection()` function that just collects and returns the top-level, filtered test labels, I think things will become a lot easier to understand and work with -- not just for `bisect_tests()` and `paired_tests()`, but also for the main `django_tests()` case.