Skip to content

Commit ad56cd8

Browse files
committed
extract a _handle_skip method, secure PY2 branch
1 parent 176c680 commit ad56cd8

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

_pytest/unittest.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -151,22 +151,30 @@ def addSuccess(self, testcase):
151151
def stopTest(self, testcase):
152152
pass
153153

154+
def _handle_skip(self):
155+
# implements the skipping machinery (see #2137)
156+
# analog to pythons Lib/unittest/case.py:run
157+
testMethod = getattr(self._testcase, self._testcase._testMethodName)
158+
if (getattr(self._testcase.__class__, "__unittest_skip__", False) or
159+
getattr(testMethod, "__unittest_skip__", False)):
160+
# If the class or method was skipped.
161+
skip_why = (getattr(self._testcase.__class__, '__unittest_skip_why__', '') or
162+
getattr(testMethod, '__unittest_skip_why__', ''))
163+
try: # PY3, unittest2 on PY2
164+
self._testcase._addSkip(self, self._testcase, skip_why)
165+
except TypeError: # PY2
166+
if sys.version_info[0] != 2:
167+
raise
168+
self._testcase._addSkip(self, skip_why)
169+
return True
170+
return False
171+
154172
def runtest(self):
155173
if self.config.pluginmanager.get_plugin("pdbinvoke") is None:
156174
self._testcase(result=self)
157175
else:
158176
# disables tearDown and cleanups for post mortem debugging (see #1890)
159-
# but still implements the skipping machinery (see #2137)
160-
testMethod = getattr(self._testcase, self._testcase._testMethodName)
161-
if (getattr(self._testcase.__class__, "__unittest_skip__", False) or
162-
getattr(testMethod, "__unittest_skip__", False)):
163-
# If the class or method was skipped.
164-
skip_why = (getattr(self._testcase.__class__, '__unittest_skip_why__', '') or
165-
getattr(testMethod, '__unittest_skip_why__', ''))
166-
try:
167-
self._testcase._addSkip(self, self._testcase, skip_why)
168-
except TypeError: # PY2
169-
self._testcase._addSkip(self, skip_why)
177+
if self._handle_skip():
170178
return
171179
self._testcase.debug()
172180

testing/test_pdb.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ def test_false(self):
107107
self.flush(child)
108108

109109
def test_pdb_unittest_skip(self, testdir):
110+
"""Test for issue #2137"""
110111
p1 = testdir.makepyfile("""
111112
import unittest
112113
@unittest.skipIf(True, 'Skipping also with pdb active')

0 commit comments

Comments
 (0)