Skip to content

Commit 038b4ac

Browse files
jimmodpgeorge
authored andcommitted
unittest: Convert to a package.
This allows a much more natural way of implementing unitttest-discover: - unittest provides unittest/__init__.py - unittest-discover provides unittest/__main__.py It also fixes an bug where unittest.py previously detected the presence of unittest-discover.py by importing an checking for the ImportError. But that could also be raised by a missing dependency. Now when you run `micropython -m unittest` without unittest-discover, you get `ImportError: no module named 'unittest.__main__'`, and without the required deps, `ImportError: no module named 'argparse'`. Signed-off-by: Jim Mussared <[email protected]>
1 parent a14226f commit 038b4ac

File tree

4 files changed

+7
-17
lines changed

4 files changed

+7
-17
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
metadata(version="0.1.0")
1+
metadata(version="0.1.1")
22

33
require("argparse")
44
require("fnmatch")
55
require("unittest")
66

7-
module("unittest_discover.py")
7+
package("unittest")

python-stdlib/unittest-discover/unittest_discover.py renamed to python-stdlib/unittest-discover/unittest/__main__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ def _dirname_filename_no_ext(path):
110110
return dirname, filename.rsplit(".", 1)[0]
111111

112112

113-
# This is called from unittest when __name__ == "__main__".
114113
def discover_main():
115114
failures = 0
116115
runner = TestRunner()
@@ -138,3 +137,6 @@ def discover_main():
138137

139138
# Terminate with non zero return code in case of failures.
140139
sys.exit(failures)
140+
141+
142+
discover_main()

python-stdlib/unittest/manifest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
metadata(version="0.10.0")
1+
metadata(version="0.10.1")
22

3-
module("unittest.py")
3+
package("unittest")

python-stdlib/unittest/unittest.py renamed to python-stdlib/unittest/unittest/__init__.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -460,15 +460,3 @@ def main(module="__main__", testRunner=None):
460460
suite = TestSuite(module.__name__)
461461
suite._load_module(module)
462462
return testRunner.run(suite)
463-
464-
465-
# Support `micropython -m unittest` (only useful if unitest-discover is
466-
# installed).
467-
if __name__ == "__main__":
468-
try:
469-
# If unitest-discover is installed, use the main() provided there.
470-
from unittest_discover import discover_main
471-
472-
discover_main()
473-
except ImportError:
474-
pass

0 commit comments

Comments
 (0)