8000 unittest-discover: Print results when no tests are found/run. · micropython/micropython-lib@f672353 · GitHub
[go: up one dir, main page]

Skip to content

Commit f672353

Browse files
pi-anldpgeorge
authored andcommitted
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.
1 parent ea21cb3 commit f672353

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed

python-stdlib/unittest-discover/manifest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
metadata(version="0.1.1")
1+
metadata(version="0.1.2")
22

33
require("argparse")
44
require("fnmatch")

python-stdlib/unittest-discover/unittest/__main__.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ def _dirname_filename_no_ext(path):
111111

112112

113113
def discover_main():
114-
failures = 0
115114
runner = TestRunner()
116115

117116
if len(sys.argv) == 1 or (
@@ -121,22 +120,27 @@ def discover_main():
121120
):
122121
# No args, or `python -m unittest discover ...`.
123122
result = _discover(runner)
124-
failures += result.failuresNum or result.errorsNum
125123
else:
124+
result = TestResult()
126125
for test_spec in sys.argv[1:]:
127126
try:
128127
os.stat(test_spec)
129128
# File exists, strip extension and import with its parent directory in sys.path.
130129
dirname, module_name = _dirname_filename_no_ext(test_spec)
131-
result = _run_test_module(runner, module_name, dirname)
130+
res = _run_test_module(runner, module_name, dirname)
132131
except OSError:
133132
# Not a file, treat as named module to import.
134-
result = _run_test_module(runner, test_spec)
133+
res = _run_test_module(runner, test_spec)
135134

136-
failures += result.failuresNum or result.errorsNum
135+
result += res
136+
137+
if not result.testsRun:
138+
# If tests are run their results are already printed.
139+
# Ensure an appropriate output is printed if no tests are found.
140+
runner.run(TestSuite())
137141

138142
# Terminate with non zero return code in case of failures.
139-
sys.exit(failures)
143+
sys.exit(result.failuresNum + result.errorsNum)
140144

141145

142146
discover_main()

python-stdlib/unittest/manifest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
metadata(version="0.10.2")
1+
metadata(version="0.10.3")
22

33
package("unittest")

python-stdlib/unittest/unittest/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,10 @@ def wasSuccessful(self):
300300
return self.errorsNum == 0 and self.failuresNum == 0
301301

302302
def printErrors(self):
303-
print()
304-
self.printErrorList(self.errors)
305-
self.printErrorList(self.failures)
303+
if self.errors or self.failures:
304+
print()
305+
self.printErrorList(self.errors)
306+
self.printErrorList(self.failures)
306307

307308
def printErrorList(self, lst):
308309
sep = "----------------------------------------------------------------------"

0 commit comments

Comments
 (0)
0