mirror of https://github.com/fail2ban/fail2ban
ENH: add more verbosity levels to be controlled while running unittests
parent
398cc73d3d
commit
9a2b41f6ad
|
@ -52,8 +52,8 @@ def get_opt_parser():
|
||||||
p.add_options([
|
p.add_options([
|
||||||
Option('-l', "--log-level", type="choice",
|
Option('-l', "--log-level", type="choice",
|
||||||
dest="log_level",
|
dest="log_level",
|
||||||
choices=('debug', 'fatal'),
|
choices=('debug', 'info', 'warn', 'error', 'fatal'),
|
||||||
default='fatal',
|
default=None,
|
||||||
help="Log level for the logger to use during running tests"),
|
help="Log level for the logger to use during running tests"),
|
||||||
])
|
])
|
||||||
|
|
||||||
|
@ -77,8 +77,16 @@ logSys = logging.getLogger("fail2ban")
|
||||||
# Add the default logging handler
|
# Add the default logging handler
|
||||||
stdout = logging.StreamHandler(sys.stdout)
|
stdout = logging.StreamHandler(sys.stdout)
|
||||||
logSys.addHandler(stdout)
|
logSys.addHandler(stdout)
|
||||||
|
if opts.log_level is not None:
|
||||||
|
# so we had explicit settings
|
||||||
logSys.setLevel(getattr(logging, opts.log_level.upper()))
|
logSys.setLevel(getattr(logging, opts.log_level.upper()))
|
||||||
|
else:
|
||||||
|
# suppress the logging but it would leave unittests' progress dots
|
||||||
|
# ticking, unless like with '-l fatal' which would be silent
|
||||||
|
# unless error occurs
|
||||||
|
logSys.setLevel(getattr(logging, 'FATAL'))
|
||||||
|
|
||||||
|
if not opts.log_level or opts.log_level != 'fatal':
|
||||||
print "Fail2ban " + version + " test suite. Please wait..."
|
print "Fail2ban " + version + " test suite. Please wait..."
|
||||||
|
|
||||||
tests = unittest.TestSuite()
|
tests = unittest.TestSuite()
|
||||||
|
@ -102,6 +110,7 @@ filters = [FilterPoll] # always available
|
||||||
# with good old unittest
|
# with good old unittest
|
||||||
try:
|
try:
|
||||||
from server.filtergamin import FilterGamin
|
from server.filtergamin import FilterGamin
|
||||||
|
# That shmug plain doesn't work and stalls things ATM
|
||||||
# filters.append(FilterGamin)
|
# filters.append(FilterGamin)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
@ -131,7 +140,13 @@ tests.addTest(unittest.makeSuite(filtertestcase.DNSUtilsTests))
|
||||||
tests.addTest(unittest.makeSuite(datedetectortestcase.DateDetectorTest))
|
tests.addTest(unittest.makeSuite(datedetectortestcase.DateDetectorTest))
|
||||||
|
|
||||||
# Tests runner
|
# Tests runner
|
||||||
testRunner = unittest.TextTestRunner()
|
testRunner = unittest.TextTestRunner(
|
||||||
|
verbosity={'debug': 3,
|
||||||
|
'info': 2,
|
||||||
|
'warn': 1,
|
||||||
|
'error': 1,
|
||||||
|
'fatal': 0,
|
||||||
|
None: 1}[opts.log_level])
|
||||||
testRunner.run(tests)
|
testRunner.run(tests)
|
||||||
|
|
||||||
# Just for the sake of it reset the TZ
|
# Just for the sake of it reset the TZ
|
||||||
|
|
Loading…
Reference in New Issue