kopia lustrzana https://github.com/micropython/micropython-lib
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
rodzic
ea21cb3fdc
commit
f672353180
|
@ -1,4 +1,4 @@
|
|||
metadata(version="0.1.1")
|
||||
metadata(version="0.1.2")
|
||||
|
||||
require("argparse")
|
||||
require("fnmatch")
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
metadata(version="0.10.2")
|
||||
metadata(version="0.10.3")
|
||||
|
||||
package("unittest")
|
||||
|
|
|
@ -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 = "----------------------------------------------------------------------"
|
||||
|
|
Ładowanie…
Reference in New Issue