From 64b27d7b7ea76a3aa92dbd3f89ce6ae7dd0d120e Mon Sep 17 00:00:00 2001 From: Naitree Zhu Date: Thu, 6 Sep 2018 22:22:35 +0800 Subject: [PATCH 1/3] bpo-34596: Fallback to a default reason when @unittest.skip is uncalled --- Lib/unittest/case.py | 5 +++++ Lib/unittest/test/test_skipping.py | 11 +++++++++++ .../Tests/2018-09-07-01-18-27.bpo-34596.r2-EGd.rst | 2 ++ 3 files changed, 18 insertions(+) create mode 100644 Misc/NEWS.d/next/Tests/2018-09-07-01-18-27.bpo-34596.r2-EGd.rst diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py index 1faa6b641f2d75..8314cd8ae6f80e 100644 --- a/Lib/unittest/case.py +++ b/Lib/unittest/case.py @@ -10,6 +10,7 @@ import collections import contextlib import traceback +import types from . import result from .util import (strclass, safe_repr, _count_diff_all_purpose, @@ -98,6 +99,10 @@ def skip_wrapper(*args, **kwargs): test_item.__unittest_skip__ = True test_item.__unittest_skip_why__ = reason return test_item + if isinstance(reason, types.FunctionType): + test_item = reason + reason = 'unconditionally' + return decorator(test_item) return decorator def skipIf(condition, reason): diff --git a/Lib/unittest/test/test_skipping.py b/Lib/unittest/test/test_skipping.py index 71f7b70e479d2e..b5d958446148c8 100644 --- a/Lib/unittest/test/test_skipping.py +++ b/Lib/unittest/test/test_skipping.py @@ -255,6 +255,17 @@ def test_1(self): 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, "unconditionally")]) if __name__ == "__main__": unittest.main() diff --git a/Misc/NEWS.d/next/Tests/2018-09-07-01-18-27.bpo-34596.r2-EGd.rst b/Misc/NEWS.d/next/Tests/2018-09-07-01-18-27.bpo-34596.r2-EGd.rst new file mode 100644 index 00000000000000..c710873607197e --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2018-09-07-01-18-27.bpo-34596.r2-EGd.rst @@ -0,0 +1,2 @@ +Fallback to a default reason when @unittest.skip is uncalled. Patch by +Naitree Zhu. From 3ceddb41b4e3a738e607594c92fdacfb654ebdae Mon Sep 17 00:00:00 2001 From: Naitree Zhu Date: Sun, 16 Sep 2018 20:28:40 +0800 Subject: [PATCH 2/3] Change default reason to empty string --- Lib/unittest/case.py | 2 +- Lib/unittest/test/test_skipping.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py index 8314cd8ae6f80e..a694aaa5ca44f0 100644 --- a/Lib/unittest/case.py +++ b/Lib/unittest/case.py @@ -101,7 +101,7 @@ def skip_wrapper(*args, **kwargs): return test_item if isinstance(reason, types.FunctionType): test_item = reason - reason = 'unconditionally' + reason = '' return decorator(test_item) return decorator diff --git a/Lib/unittest/test/test_skipping.py b/Lib/unittest/test/test_skipping.py index b5d958446148c8..1c178a95f750ff 100644 --- a/Lib/unittest/test/test_skipping.py +++ b/Lib/unittest/test/test_skipping.py @@ -265,7 +265,7 @@ def test_1(self): test = Foo("test_1") suite = unittest.TestSuite([test]) suite.run(result) - self.assertEqual(result.skipped, [(test, "unconditionally")]) + self.assertEqual(result.skipped, [(test, "")]) if __name__ == "__main__": unittest.main() From fbf2cdc91efb6fb457912b63088ebcbe64dd2ecf Mon Sep 17 00:00:00 2001 From: Naitree Zhu Date: Sun, 16 Sep 2018 20:31:23 +0800 Subject: [PATCH 3/3] Fix rst formatting of NEWS entry --- Misc/NEWS.d/next/Tests/2018-09-07-01-18-27.bpo-34596.r2-EGd.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Tests/2018-09-07-01-18-27.bpo-34596.r2-EGd.rst b/Misc/NEWS.d/next/Tests/2018-09-07-01-18-27.bpo-34596.r2-EGd.rst index c710873607197e..156e8aa8945de4 100644 --- a/Misc/NEWS.d/next/Tests/2018-09-07-01-18-27.bpo-34596.r2-EGd.rst +++ b/Misc/NEWS.d/next/Tests/2018-09-07-01-18-27.bpo-34596.r2-EGd.rst @@ -1,2 +1,2 @@ -Fallback to a default reason when @unittest.skip is uncalled. Patch by +Fallback to a default reason when :func:`unittest.skip` is uncalled. Patch by Naitree Zhu.