Fix unittest.skip decorator test and separate the fix into a different, self-doc function
This commit is contained in:
parent
313050b15b
commit
7d6edb9ca5
|
@ -69,22 +69,26 @@ class TestCaseFunction(pytest.Function):
|
|||
|
||||
def setup(self):
|
||||
self._testcase = self.parent.obj(self.name)
|
||||
#
|
||||
# See issue #1169
|
||||
#
|
||||
# The @unittest.skip decorator calls functools.wraps(self._testcase)
|
||||
# The call to functools.wraps() fails unless self._testcase
|
||||
# has a __name__ attribute. This is usually automatically supplied
|
||||
# if the test is a function or method, but we need to add manually
|
||||
# here.
|
||||
#
|
||||
setattr(self._testcase, "__name__", self.name)
|
||||
self._fix_unittest_skip_decorator()
|
||||
self._obj = getattr(self._testcase, self.name)
|
||||
if hasattr(self._testcase, 'setup_method'):
|
||||
self._testcase.setup_method(self._obj)
|
||||
if hasattr(self, "_request"):
|
||||
self._request._fillfixtures()
|
||||
|
||||
def _fix_unittest_skip_decorator(self):
|
||||
"""
|
||||
The @unittest.skip decorator calls functools.wraps(self._testcase)
|
||||
The call to functools.wraps() fails unless self._testcase
|
||||
has a __name__ attribute. This is usually automatically supplied
|
||||
if the test is a function or method, but we need to add manually
|
||||
here.
|
||||
|
||||
See issue #1169
|
||||
"""
|
||||
if sys.version_info[0] == 2:
|
||||
setattr(self._testcase, "__name__", self.name)
|
||||
|
||||
def teardown(self):
|
||||
if hasattr(self._testcase, 'teardown_method'):
|
||||
self._testcase.teardown_method(self._obj)
|
||||
|
|
|
@ -721,14 +721,16 @@ def test_unittest_raise_skip_issue748(testdir):
|
|||
|
||||
@pytest.mark.skipif("sys.version_info < (2,7)")
|
||||
def test_unittest_skip_issue1169(testdir):
|
||||
testpath = testdir.makepyfile(test_foo="""
|
||||
testdir.makepyfile(test_foo="""
|
||||
import unittest
|
||||
|
||||
class MyTestCase(unittest.TestCase):
|
||||
@unittest.skip
|
||||
@unittest.skip("skipping due to reasons")
|
||||
def test_skip(self):
|
||||
self.fail()
|
||||
""")
|
||||
reprec = testdir.inline_run(testpath)
|
||||
reprec.assertoutcome(passed=1)
|
||||
|
||||
result = testdir.runpytest("-v", '-rs')
|
||||
result.stdout.fnmatch_lines("""
|
||||
*SKIP*[1]*skipping due to reasons*
|
||||
*1 skipped*
|
||||
""")
|
||||
|
|
Loading…
Reference in New Issue