Use mock.patch for all logging tests
@@ -107,15 +107,14 @@ class AccessLogTests(helper.CPWebCase, logtest.LogCase):
self.assertLog(-1, '] "GET %s/as_yield HTTP/1.1" 200 - "" ""'
% self.prefix())
+ @mock.patch(
+ 'cherrypy._cplogging.LogManager.access_log_format',
+ '{h} {l} {u} {t} "{r}" {s} {b} "{f}" "{a}" {o}'
+ if six.PY3 else
+ '%(h)s %(l)s %(u)s %(z)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s" %(o)s'
+ )
def testCustomLogFormat(self):
"""Test a customized access_log_format string, which is a feature of _cplogging.LogManager.access()."""
- original_logformat = cherrypy._cplogging.LogManager.access_log_format
- cherrypy._cplogging.LogManager.access_log_format = (
- '{h} {l} {u} {t} "{r}" {s} {b} "{f}" "{a}" {o}' if six.PY3
- else
- '%(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s" %(o)s'
- )
-
self.markLog()
self.getPage('/as_string', headers=[('Referer', 'REFERER'),
('User-Agent', 'USERAGENT'),
@@ -124,17 +123,14 @@ class AccessLogTests(helper.CPWebCase, logtest.LogCase):
self.assertLog(-1, '] "GET /as_string HTTP/1.1" '
'200 7 "REFERER" "USERAGENT" HOST')
- cherrypy._cplogging.LogManager.access_log_format = original_logformat
-
- def testTimezLogFormat(self):
- """Test a customized access_log_format string, which is a feature of _cplogging.LogManager.access()."""
- original_logformat = cherrypy._cplogging.LogManager.access_log_format
- cherrypy._cplogging.LogManager.access_log_format = (
- '{h} {l} {u} {z} "{r}" {s} {b} "{f}" "{a}" {o}' if six.PY3
- else
+ @mock.patch(
+ 'cherrypy._cplogging.LogManager.access_log_format',
+ '{h} {l} {u} {z} "{r}" {s} {b} "{f}" "{a}" {o}'
+ if six.PY3 else
'%(h)s %(l)s %(u)s %(z)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s" %(o)s'
)
-
+ def testTimezLogFormat(self):
+ """Test a customized access_log_format string, which is a feature of _cplogging.LogManager.access()."""
self.markLog()
self.getPage('/as_string', headers=[('Referer', 'REFERER'),
('User-Agent', 'USERAGENT'),
@@ -143,8 +139,6 @@ class AccessLogTests(helper.CPWebCase, logtest.LogCase):
self.assertLog(-1, ' "GET /as_string HTTP/1.1" '
'200 7 "REFERER" "USERAGENT" HOST')
- cherrypy._cplogging.LogManager.access_log_format = original_logformat
-
@mock.patch(
'cherrypy._cplogging.LogManager.access_log_format',
'{i}' if six.PY3 else '%(i)s'
