mirror of
https://github.com/python/cpython.git
synced 2025-08-15 06:10:47 +00:00
bpo-34596: Fallback to a default reason when @unittest.skip is uncalled (GH-9082) (#15781)
* 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 d5fd75c53f
)
Co-authored-by: Naitree Zhu <Naitreey@gmail.com>
This commit is contained in:
parent
cabcbbe7a5
commit
3bd4bed78a
3 changed files with 18 additions and 0 deletions
|
@ -10,6 +10,7 @@ import warnings
|
||||||
import collections
|
import collections
|
||||||
import contextlib
|
import contextlib
|
||||||
import traceback
|
import traceback
|
||||||
|
import types
|
||||||
|
|
||||||
from . import result
|
from . import result
|
||||||
from .util import (strclass, safe_repr, _count_diff_all_purpose,
|
from .util import (strclass, safe_repr, _count_diff_all_purpose,
|
||||||
|
@ -122,6 +123,10 @@ def skip(reason):
|
||||||
test_item.__unittest_skip__ = True
|
test_item.__unittest_skip__ = True
|
||||||
test_item.__unittest_skip_why__ = reason
|
test_item.__unittest_skip_why__ = reason
|
||||||
return test_item
|
return test_item
|
||||||
|
if isinstance(reason, types.FunctionType):
|
||||||
|
test_item = reason
|
||||||
|
reason = ''
|
||||||
|
return decorator(test_item)
|
||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
def skipIf(condition, reason):
|
def skipIf(condition, reason):
|
||||||
|
|
|
@ -255,6 +255,17 @@ class Test_TestSkipping(unittest.TestCase):
|
||||||
suite.run(result)
|
suite.run(result)
|
||||||
self.assertEqual(result.skipped, [(test, "testing")])
|
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__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Fallback to a default reason when :func:`unittest.skip` is uncalled. Patch by
|
||||||
|
Naitree Zhu.
|
Loading…
Add table
Add a link
Reference in a new issue