From 1c5c70a2447251593e5ae2e092d6487168315413 Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Sat, 6 Oct 2012 17:11:45 +0300 Subject: Issue #16120: Use |yield from| in stdlib. Patch by Berker Peksag. --- Lib/unittest/loader.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'Lib/unittest/loader.py') diff --git a/Lib/unittest/loader.py b/Lib/unittest/loader.py index 541884e416..a5ac737fc2 100644 --- a/Lib/unittest/loader.py +++ b/Lib/unittest/loader.py @@ -291,8 +291,7 @@ class TestLoader(object): # tests loaded from package file yield tests # recurse into the package - for test in self._find_tests(full_path, pattern): - yield test + yield from self._find_tests(full_path, pattern) else: try: yield load_tests(self, tests, pattern) -- cgit v1.2.1 From 90ed202c9e3d04d8a64f9be221b7678f6dbb2fc6 Mon Sep 17 00:00:00 2001 From: Ezio Melotti Date: Fri, 1 Mar 2013 14:47:50 +0200 Subject: #16935: unittest now counts the module as skipped if it raises SkipTest, instead of counting it as an error. Patch by Zachary Ware. --- Lib/unittest/loader.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'Lib/unittest/loader.py') diff --git a/Lib/unittest/loader.py b/Lib/unittest/loader.py index a5ac737fc2..2077fa3cdb 100644 --- a/Lib/unittest/loader.py +++ b/Lib/unittest/loader.py @@ -34,6 +34,14 @@ def _make_failed_test(classname, methodname, exception, suiteClass): TestClass = type(classname, (case.TestCase,), attrs) return suiteClass((TestClass(methodname),)) +def _make_skipped_test(methodname, exception, suiteClass): + @case.skip(str(exception)) + def testSkipped(self): + pass + attrs = {methodname: testSkipped} + TestClass = type("ModuleSkipped", (case.TestCase,), attrs) + return suiteClass((TestClass(methodname),)) + def _jython_aware_splitext(path): if path.lower().endswith('$py.class'): return path[:-9] @@ -259,6 +267,8 @@ class TestLoader(object): name = self._get_name_from_path(full_path) try: module = self._get_module_from_name(name) + except case.SkipTest as e: + yield _make_skipped_test(name, e, self.suiteClass) except: yield _make_failed_import_test(name, self.suiteClass) else: -- cgit v1.2.1 From 73c77eae61e56daeff2640dac661f3db4de1cf79 Mon Sep 17 00:00:00 2001 From: Michael Foord Date: Mon, 18 Mar 2013 17:50:12 -0700 Subject: Closes issue 16709. unittest test discovery sorts test files for consistent test ordering --- Lib/unittest/loader.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'Lib/unittest/loader.py') diff --git a/Lib/unittest/loader.py b/Lib/unittest/loader.py index 2077fa3cdb..25a91227de 100644 --- a/Lib/unittest/loader.py +++ b/Lib/unittest/loader.py @@ -177,6 +177,9 @@ class TestLoader(object): The pattern is deliberately not stored as a loader attribute so that packages can continue discovery themselves. top_level_dir is stored so load_tests does not need to pass this argument in to loader.discover(). + + Paths are sorted before being imported to ensure reproducible execution + order even on filesystems with non-alphabetical ordering like ext3/4. """ set_implicit_top = False if top_level_dir is None and self._top_level_dir is not None: @@ -253,7 +256,7 @@ class TestLoader(object): def _find_tests(self, start_dir, pattern): """Used by discovery. Yields test suites it loads.""" - paths = os.listdir(start_dir) + paths = sorted(os.listdir(start_dir)) for path in paths: full_path = os.path.join(start_dir, path) -- cgit v1.2.1