Changes between Initial Version and Version 1 of Ticket #32668


Ignore:
Timestamp:
Apr 20, 2021, 6:43:31 PM (4 years ago)
Author:
Chris Jerdonek
Comment:

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].
     1This 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].
    22
    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.)
     3TLDR: 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.)
    44
    55Longer version:
     
    77Currently, `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.
    88
    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):
     9There 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):
    1010`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`.
    1111
    12 By extracting out from `setup()` a `setup_test_collection()` function that just collects and returns the 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.
     12By 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.
Back to Top