itests: add a command-line parameter to enable debug logs
This commit is contained in:
parent
c486c0e821
commit
40196aefeb
1 changed files with 9 additions and 5 deletions
|
@ -10,7 +10,7 @@ from importlib import import_module
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
def run_tests(filenames=None):
|
def run_tests(filenames=None, debug=False):
|
||||||
"""
|
"""
|
||||||
Find and run all tests in the tests/ directory.
|
Find and run all tests in the tests/ directory.
|
||||||
|
|
||||||
|
@ -33,9 +33,12 @@ def run_tests(filenames=None):
|
||||||
tests = unittest.TestSuite(suites)
|
tests = unittest.TestSuite(suites)
|
||||||
runner = unittest.TextTestRunner(verbosity=2)
|
runner = unittest.TextTestRunner(verbosity=2)
|
||||||
|
|
||||||
# Disable logging output
|
if debug:
|
||||||
logging.basicConfig(level=100)
|
logging.basicConfig(level='DEBUG')
|
||||||
logging.disable(100)
|
else:
|
||||||
|
# Disable logging output
|
||||||
|
logging.basicConfig(level=100)
|
||||||
|
logging.disable(100)
|
||||||
|
|
||||||
result = runner.run(tests)
|
result = runner.run(tests)
|
||||||
return result
|
return result
|
||||||
|
@ -60,9 +63,10 @@ class TestCommand(Command):
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
parser = ArgumentParser(description='Run unit tests.')
|
parser = ArgumentParser(description='Run unit tests.')
|
||||||
parser.add_argument('tests', metavar='TEST', nargs='*', help='list of tests to run, or nothing to run them all')
|
parser.add_argument('tests', metavar='TEST', nargs='*', help='list of tests to run, or nothing to run them all')
|
||||||
|
parser.add_argument('-d', '--debug', action='store_true', dest='debug', default=False, help='enable debug output')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
result = run_tests(args.tests)
|
result = run_tests(args.tests, args.debug)
|
||||||
print("<tests %s ran='%s' errors='%s' fails='%s' success='%s'/>" % (
|
print("<tests %s ran='%s' errors='%s' fails='%s' success='%s'/>" % (
|
||||||
"xmlns='http//andyet.net/protocol/tests'",
|
"xmlns='http//andyet.net/protocol/tests'",
|
||||||
result.testsRun, len(result.errors),
|
result.testsRun, len(result.errors),
|
||||||
|
|
Loading…
Reference in a new issue