Merge pull request #1171 from nicoddemus/fix-1169
Allow @unittest.skip decorators in Python 2.7
This commit is contained in:
commit
98668c943d
1
AUTHORS
1
AUTHORS
|
@ -46,6 +46,7 @@ Jason R. Coombs
|
||||||
Jurko Gospodnetić
|
Jurko Gospodnetić
|
||||||
Katarzyna Jachim
|
Katarzyna Jachim
|
||||||
Kevin Cox
|
Kevin Cox
|
||||||
|
Lee Kamentsky
|
||||||
Maciek Fijalkowski
|
Maciek Fijalkowski
|
||||||
Maho
|
Maho
|
||||||
Marc Schlaich
|
Marc Schlaich
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
2.8.3.dev
|
2.8.3.dev
|
||||||
---------
|
---------
|
||||||
|
|
||||||
|
- fix #1169: add __name__ attribute to testcases in TestCaseFunction to
|
||||||
|
support the @unittest.skip decorator on functions and methods.
|
||||||
|
Thanks Lee Kamentsky for the PR.
|
||||||
|
|
||||||
- fix #1035: collecting tests if test module level obj has __getattr__().
|
- fix #1035: collecting tests if test module level obj has __getattr__().
|
||||||
Thanks Suor for the report and Bruno Oliveira / Tom Viner for the PR.
|
Thanks Suor for the report and Bruno Oliveira / Tom Viner for the PR.
|
||||||
|
|
||||||
|
|
|
@ -69,12 +69,26 @@ class TestCaseFunction(pytest.Function):
|
||||||
|
|
||||||
def setup(self):
|
def setup(self):
|
||||||
self._testcase = self.parent.obj(self.name)
|
self._testcase = self.parent.obj(self.name)
|
||||||
|
self._fix_unittest_skip_decorator()
|
||||||
self._obj = getattr(self._testcase, self.name)
|
self._obj = getattr(self._testcase, self.name)
|
||||||
if hasattr(self._testcase, 'setup_method'):
|
if hasattr(self._testcase, 'setup_method'):
|
||||||
self._testcase.setup_method(self._obj)
|
self._testcase.setup_method(self._obj)
|
||||||
if hasattr(self, "_request"):
|
if hasattr(self, "_request"):
|
||||||
self._request._fillfixtures()
|
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):
|
def teardown(self):
|
||||||
if hasattr(self._testcase, 'teardown_method'):
|
if hasattr(self._testcase, 'teardown_method'):
|
||||||
self._testcase.teardown_method(self._obj)
|
self._testcase.teardown_method(self._obj)
|
||||||
|
|
|
@ -718,3 +718,19 @@ def test_unittest_raise_skip_issue748(testdir):
|
||||||
*SKIP*[1]*test_foo.py*skipping due to reasons*
|
*SKIP*[1]*test_foo.py*skipping due to reasons*
|
||||||
*1 skipped*
|
*1 skipped*
|
||||||
""")
|
""")
|
||||||
|
|
||||||
|
@pytest.mark.skipif("sys.version_info < (2,7)")
|
||||||
|
def test_unittest_skip_issue1169(testdir):
|
||||||
|
testdir.makepyfile(test_foo="""
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
class MyTestCase(unittest.TestCase):
|
||||||
|
@unittest.skip("skipping due to reasons")
|
||||||
|
def test_skip(self):
|
||||||
|
self.fail()
|
||||||
|
""")
|
||||||
|
result = testdir.runpytest("-v", '-rs')
|
||||||
|
result.stdout.fnmatch_lines("""
|
||||||
|
*SKIP*[1]*skipping due to reasons*
|
||||||
|
*1 skipped*
|
||||||
|
""")
|
||||||
|
|
Loading…
Reference in New Issue