From: Michael Orlitzky Date: Tue, 21 Apr 2020 11:40:52 +0000 (-0400) Subject: test: add the ability to run the test suite verbosely. X-Git-Tag: 0.1.2~13 X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=4a9928501f79549742c2e335742ddc65040f744f;p=dunshire.git test: add the ability to run the test suite verbosely. This commit adds a "check-verbose" target that runs the test suite, outputting the name and result of each test as it goes. This mimics what "python setup.py test" does, but that command is apparently deprecated; so now the usual test entry point can do it too. --- diff --git a/makefile b/makefile index 1220965..becaa91 100644 --- a/makefile +++ b/makefile @@ -21,6 +21,13 @@ doctest: check: PYTHONPATH="." test/__main__.py +# Run the test suite once, loudly. This is used in Gentoo, for example +# where we want users to see the output from the test suite on the off +# chance that it fails and they have to report it. +.PHONY: check-verbose +check-verbose: + PYTHONPATH="." test/__main__.py --verbose + # Run the test suite forever, but only the parts of it that are # randomized. .PHONY: checkloop diff --git a/test/__init__.py b/test/__init__.py index 8c0de9e..28d90a6 100644 --- a/test/__init__.py +++ b/test/__init__.py @@ -44,10 +44,10 @@ def build_suite(doctests=True): suite.addTest(mat_tests) return suite -def run_suite(suite): +def run_suite(suite, verbosity): """ Run all of the unit and doctests for the :mod:`dunshire` and :mod:`test` packages. """ - runner = TextTestRunner(verbosity=1) + runner = TextTestRunner(verbosity=verbosity) return runner.run(suite) diff --git a/test/__main__.py b/test/__main__.py index d4ef145..c8f0f24 100755 --- a/test/__main__.py +++ b/test/__main__.py @@ -7,7 +7,7 @@ from sys import argv from test import build_suite, run_suite -def main(doctests, loop): +def main(doctests, loop, verbose): """ The main function for this module. It runs the tests. @@ -26,11 +26,17 @@ def main(doctests, loop): loop : bool Do you want to loop and rerun the tests indefinitely? + verbose : bool + Do you want to see the name and result of each test as + it is run? + """ # Running the test suite clobbers it! And deepcopy() doesn't work # on a suite that contains doctests! ARRRGRRGRRGRHG!!!!!! You're all # idiots. - result = run_suite(build_suite(doctests)) + verbosity = 1 + if verbose: verbosity = 2 + result = run_suite(build_suite(doctests), verbosity) if result.wasSuccessful() and not loop: return 0 @@ -40,10 +46,13 @@ def main(doctests, loop): while result.wasSuccessful(): print('Passed: {:d}'.format(passed)) passed += 1 - result = run_suite(build_suite(doctests)) + result = run_suite(build_suite(doctests), verbosity) return 1 if __name__ == '__main__': - exit(main(not "--no-doctests" in argv, '--loop' in argv)) + doctests = not "--no-doctests" in argv + loop = '--loop' in argv + verbose = '--verbose' in argv + exit(main(doctests, loop, verbose))