#36083: LiveServerTestCase fails in parallel test runner if
django.contrib.auth.backends has not yet been imported
-------------------------------------+-------------------------------------
     Reporter:  Adam Zapletal        |                    Owner:  Jacob
                                     |  Walls
         Type:  Bug                  |                   Status:  assigned
    Component:  Testing framework    |                  Version:  dev
     Severity:  Release blocker      |               Resolution:
     Keywords:  TransactionTestCase  |             Triage Stage:  Accepted
  setupclass available_apps          |
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Comment (by Jacob Walls):

 Unfortunately there is a new test failure with option 2, so it's probably
 less safe than doing nothing:

 {{{
 ======================================================================
 ERROR: test_media_files (servers.tests.LiveServerViews.test_media_files)
 ----------------------------------------------------------------------
 Traceback (most recent call last):
   File "/Users/user/django/tests/servers/tests.py", line 310, in
 test_media_files
     with self.urlopen("/media/example_media_file.txt") as f:
          ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   File "/Users/user/django/tests/servers/tests.py", line 44, in urlopen
     return urlopen(self.live_server_url + url)
   File
 
"/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/urllib/request.py",
 line 189, in urlopen
     return opener.open(url, data, timeout)
            ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
   File
 
"/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/urllib/request.py",
 line 495, in open
     response = meth(req, response)
   File
 
"/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/urllib/request.py",
 line 604, in http_response
     response = self.parent.error(
         'http', request, response, code, msg, hdrs)
   File
 
"/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/urllib/request.py",
 line 533, in error
     return self._call_chain(*args)
            ~~~~~~~~~~~~~~~~^^^^^^^
   File
 
"/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/urllib/request.py",
 line 466, in _call_chain
     result = func(*args)
   File
 
"/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/urllib/request.py",
 line 613, in http_error_default
     raise HTTPError(req.full_url, code, msg, hdrs, fp)
 urllib.error.HTTPError: HTTP Error 404: Not Found

 ----------------------------------------------------------------------
 Ran 30 tests in 5.779s
 }}}

 ----
 For reference here is the test I was intending to add:
 {{{
 class LiveServerAvailableAppsTests(LiveServerTestCase):
     available_apps = []

     @classmethod
     def setUpClass(cls):
         # Simulate the system checks having not run their side effect of
         # importing these modules via check_middleware().
         auth_backends = sys.modules.pop("django.contrib.auth.backends",
 None)
         cls.addClassCleanup(sys.modules.__setitem__,
 "django.contrib.auth.backends", auth_backends)
         auth_middleware =
 sys.modules.pop("django.contrib.auth.middleware", None)
         cls.addClassCleanup(sys.modules.__setitem__,
 "django.contrib.auth.middleware", auth_middleware)

         super().setUpClass()

     def test_server_starts_when_system_checks_have_not_run(self):
         # Mostly to exercise setUpClass() but also to verify test setup.
         self.assertEqual(self.available_apps, [])
 }}}

 ----
 Option 3 (Adam's original patch) may be the most practical thing at this
 point (and doesn't need to be a blocker, since it's just changing our
 existing test.)

 Thoughts?
-- 
Ticket URL: <https://code.djangoproject.com/ticket/36083#comment:15>
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 visit 
https://groups.google.com/d/msgid/django-updates/010701946a703c0f-2c652810-8bc5-4c9a-a511-cdb6ba96c579-000000%40eu-central-1.amazonses.com.

Reply via email to