Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
* Rewrite __init__.py and __main__.py
  • Loading branch information
vstinner committed Jun 20, 2022
commit 34a8a1b6ed71a43c1a4670bf3141f4b88dae4f41
27 changes: 4 additions & 23 deletions Lib/test/test_unittest/__init__.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,6 @@
import os
import sys
import unittest
import os.path
from test.support import load_package_tests


here = os.path.dirname(__file__)
loader = unittest.defaultTestLoader

def suite():
suite = unittest.TestSuite()
for fn in os.listdir(here):
if fn.startswith("test") and fn.endswith(".py"):
modname = "test.test_unittest." + fn[:-3]
try:
__import__(modname)
except unittest.SkipTest:
continue
module = sys.modules[modname]
suite.addTest(loader.loadTestsFromModule(module))
suite.addTest(loader.loadTestsFromName('test.test_unittest.testmock'))
return suite


if __name__ == "__main__":
unittest.main(defaultTest="suite")
def load_tests(*args):
return load_package_tests(os.path.dirname(__file__), *args)
18 changes: 2 additions & 16 deletions Lib/test/test_unittest/__main__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,4 @@
import os
from . import load_tests
import unittest


def load_tests(loader, standard_tests, pattern):
# top level directory cached on loader instance
this_dir = os.path.dirname(__file__)
pattern = pattern or "test_*.py"
# We are inside test.test_unittest, so the top-level is two notches up
top_level_dir = os.path.dirname(os.path.dirname(this_dir))
package_tests = loader.discover(start_dir=this_dir, pattern=pattern,
top_level_dir=top_level_dir)
standard_tests.addTests(package_tests)
return standard_tests


if __name__ == '__main__':
unittest.main()
unittest.main()