* bpo-34596: Fallback to a default reason when @unittest.skip is uncalled
* Change default reason to empty string
* Fix rst formatting of NEWS entry
(cherry picked from commit
d5fd75c53fad7049fc640c9a6162d35f0c5bea03)
Co-authored-by: Naitree Zhu <Naitreey@gmail.com>
import collections
import contextlib
import traceback
+import types
from . import result
from .util import (strclass, safe_repr, _count_diff_all_purpose,
test_item.__unittest_skip__ = True
test_item.__unittest_skip_why__ = reason
return test_item
+ if isinstance(reason, types.FunctionType):
+ test_item = reason
+ reason = ''
+ return decorator(test_item)
return decorator
def skipIf(condition, reason):
suite.run(result)
self.assertEqual(result.skipped, [(test, "testing")])
+ def test_skip_without_reason(self):
+ class Foo(unittest.TestCase):
+ @unittest.skip
+ def test_1(self):
+ pass
+
+ result = unittest.TestResult()
+ test = Foo("test_1")
+ suite = unittest.TestSuite([test])
+ suite.run(result)
+ self.assertEqual(result.skipped, [(test, "")])
if __name__ == "__main__":
unittest.main()
--- /dev/null
+Fallback to a default reason when :func:`unittest.skip` is uncalled. Patch by
+Naitree Zhu.