unittest-discover: Print results when no tests are found/run.

Prior to this commit, if no tests were found when running unittest discover
then nothing at all was written to stdout, leading one to think it's not
working at all.  CPython unittest does display a "0 tests run" sort of
output in such a case, and this commit ensures this package does the same.
pull/630/head
Andrew Leech 2023-03-16 11:00:22 +11:00 zatwierdzone przez Damien George
rodzic ea21cb3fdc
commit f672353180
4 zmienionych plików z 16 dodań i 11 usunięć

Wyświetl plik

@ -1,4 +1,4 @@
metadata(version="0.1.1")
metadata(version="0.1.2")
require("argparse")
require("fnmatch")

Wyświetl plik

@ -111,7 +111,6 @@ def _dirname_filename_no_ext(path):
def discover_main():
failures = 0
runner = TestRunner()
if len(sys.argv) == 1 or (
@ -121,22 +120,27 @@ def discover_main():
):
# No args, or `python -m unittest discover ...`.
result = _discover(runner)
failures += result.failuresNum or result.errorsNum
else:
result = TestResult()
for test_spec in sys.argv[1:]:
try:
os.stat(test_spec)
# File exists, strip extension and import with its parent directory in sys.path.
dirname, module_name = _dirname_filename_no_ext(test_spec)
result = _run_test_module(runner, module_name, dirname)
res = _run_test_module(runner, module_name, dirname)
except OSError:
# Not a file, treat as named module to import.
result = _run_test_module(runner, test_spec)
res = _run_test_module(runner, test_spec)
failures += result.failuresNum or result.errorsNum
result += res
if not result.testsRun:
# If tests are run their results are already printed.
# Ensure an appropriate output is printed if no tests are found.
runner.run(TestSuite())
# Terminate with non zero return code in case of failures.
sys.exit(failures)
sys.exit(result.failuresNum + result.errorsNum)
discover_main()

Wyświetl plik

@ -1,3 +1,3 @@
metadata(version="0.10.2")
metadata(version="0.10.3")
package("unittest")

Wyświetl plik

@ -300,9 +300,10 @@ class TestResult:
return self.errorsNum == 0 and self.failuresNum == 0
def printErrors(self):
print()
self.printErrorList(self.errors)
self.printErrorList(self.failures)
if self.errors or self.failures:
print()
self.printErrorList(self.errors)
self.printErrorList(self.failures)
def printErrorList(self, lst):
sep = "----------------------------------------------------------------------"