Suggested edits by Bruno.

Moved fix to TestCaseFunction.setup. Added myself to AUTHORS and added entry to CHANGELOG
This commit is contained in:
Lee Kamentsky 2015-11-04 15:30:16 -05:00
parent 1833547936
commit 313050b15b
4 changed files with 15 additions and 1 deletions

View File

@ -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

View File

@ -1,6 +1,9 @@
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.
- 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.

View File

@ -69,6 +69,16 @@ class TestCaseFunction(pytest.Function):
def setup(self): def setup(self):
self._testcase = self.parent.obj(self.name) 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._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)
@ -134,7 +144,6 @@ class TestCaseFunction(pytest.Function):
pass pass
def runtest(self): def runtest(self):
setattr(self._testcase, "__name__", self.name)
self._testcase(result=self) self._testcase(result=self)
def _prunetraceback(self, excinfo): def _prunetraceback(self, excinfo):

View File

@ -719,6 +719,7 @@ def test_unittest_raise_skip_issue748(testdir):
*1 skipped* *1 skipped*
""") """)
@pytest.mark.skipif("sys.version_info < (2,7)")
def test_unittest_skip_issue1169(testdir): def test_unittest_skip_issue1169(testdir):
testpath = testdir.makepyfile(test_foo=""" testpath = testdir.makepyfile(test_foo="""
import unittest import unittest