Opened 13 months ago

Last modified 3 months ago

#22439 assigned Cleanup/optimization

LiveServerTestCase handles error messages inconsistently

Reported by: jmbowman Owned by: jmbowman
Component: Testing framework Version: 1.6
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: yes
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

There are a few different ways that messages can be output when running LiveServerTestCase, and they aren't currently handled consistently:

  • Messages that are created via the logging module are handled normally with the exception of console output, which is typically captured by the test runner and shown only for failures. This is usually what is desired.
  • Request status messages are normally sent to stdout by Django's WSGIRequestHandler, but QuietWSGIRequestHandler doesn't output them at all to avoid interfering with the test runner output. This makes the information unavailable when debugging test failures.
  • PEP 333 (WSGI) suggests sending error messages to the wsgi.errors stream, which even for QuietWSGIRequestHandler is currently stderr. These can interfere with the test runner output.
  • Some less serious errors instead get sent to socketserver.BaseServer.handle_error() (inherited by WSGIServer), which since at least Python 2.7 has sent different parts of the output directly to stdout and stderr (there's a comment in the CPython source pointing out that this is less than ideal). Errors like "[Errno 32] Broken pipe" (which sometimes happens when a browser cancels a request before it finishes) can end up here and really clutter the test output.

None of this should go to stderr or stdout when running a LiveServerTestCase, and most (maybe all) of it should be available via the configured logging handlers (probably via the "django.request" logger).

Change History (7)

comment:1 Changed 13 months ago by jmbowman

  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to jmbowman
  • Patch needs improvement unset
  • Status changed from new to assigned

comment:2 Changed 13 months ago by jmbowman

  • Has patch set

Proposed fix is in https://github.com/jmbowman/django/tree/ticket_22439 (now looking into possible unit tests for it).

comment:3 Changed 13 months ago by julien

  • Needs documentation set
  • Triage Stage changed from Unreviewed to Accepted

comment:4 Changed 12 months ago by jmbowman

Unit tests are written and passing in at least Python 2.7 and 3.4. Pull request has been generated and is ready for review: https://github.com/django/django/pull/2557

comment:5 Changed 12 months ago by julien

Thanks a lot, the patch looks great. Could you just add a little bit of documentation explaining how information/errors are logged with LSTC, so the user knows where to look?

Last edited 12 months ago by julien (previous) (diff)

comment:6 Changed 12 months ago by ramiro

As noted in a comment there. This would also solve issue #21227.

comment:7 Changed 3 months ago by jaywink

Tested by merging (and resolving conflicts) on top of 1.6.10 at least and works well.

Incidentally, the "Errors like "[Errno 32] Broken pipe" (which sometimes happens when a browser cancels a request before it finishes) can end up here and really clutter the test output. " part is also solved by this commit going to 1.8 next release: https://github.com/django/django/commit/9253042d53d61b23b3f727a00c41e8089be73836 . Verified merging this in to 1.6.10 this too.

Note: See TracTickets for help on using tickets.
Back to Top