Commit c8e0fb25 by Ned Batchelder

Mock servers shouldn't pollute test output.

BY writing to stderr, BaseHTTPRequestHandler writes log messages to the
console during testing.  This makes the output harder to interpret.
Write the log messages to stdout instead, so that test runners will
suppress them during passing tests, and show them during failing tests.

It would be nice to have a place to write this method just once for the
Youtube and LTI mock servers, but we don't seem to have a place for code
as common as that.
parent 336d648e
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
import urlparse
import json
import mock
import sys
import threading
import json
import time
import urlparse
from logging import getLogger
logger = getLogger(__name__)
import time
class MockYoutubeRequestHandler(BaseHTTPRequestHandler):
'''
......@@ -14,6 +17,15 @@ class MockYoutubeRequestHandler(BaseHTTPRequestHandler):
protocol = "HTTP/1.0"
def log_message(self, format, *args):
"""Log an arbitrary message."""
# Code copied from BaseHTTPServer.py. Changed to write to sys.stdout
# so that messages won't pollute test output.
sys.stdout.write("%s - - [%s] %s\n" %
(self.client_address[0],
self.log_date_time_string(),
format % args))
def do_HEAD(self):
code = 200
if 'test_transcripts_youtube' in self.path:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment