#32668: Separate test-collection setup from runtests.py's setup() for use in
get_app_test_labels()
------------------------------------------------+------------------------
Reporter: Chris Jerdonek | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Testing framework | Version: dev
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
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].
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.)
Longer version:
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.
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):
`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`.
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/32668>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/052.d31a0b499475a65dde3882a8faba0bea%40djangoproject.com.