Skip to content

Commit

Permalink
extract a _handle_skip method, secure PY2 branch
Browse files Browse the repository at this point in the history
  • Loading branch information
mbyt committed Feb 2, 2017
1 parent 176c680 commit ad56cd8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
30 changes: 19 additions & 11 deletions _pytest/unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,22 +151,30 @@ def addSuccess(self, testcase):
def stopTest(self, testcase):
pass

def _handle_skip(self):
# implements the skipping machinery (see #2137)
# analog to pythons Lib/unittest/case.py:run
testMethod = getattr(self._testcase, self._testcase._testMethodName)
if (getattr(self._testcase.__class__, "__unittest_skip__", False) or
getattr(testMethod, "__unittest_skip__", False)):
# If the class or method was skipped.
skip_why = (getattr(self._testcase.__class__, '__unittest_skip_why__', '') or
getattr(testMethod, '__unittest_skip_why__', ''))
try: # PY3, unittest2 on PY2
self._testcase._addSkip(self, self._testcase, skip_why)
except TypeError: # PY2
if sys.version_info[0] != 2:
raise
self._testcase._addSkip(self, skip_why)
return True
return False

def runtest(self):
if self.config.pluginmanager.get_plugin("pdbinvoke") is None:
self._testcase(result=self)
else:
# disables tearDown and cleanups for post mortem debugging (see #1890)
# but still implements the skipping machinery (see #2137)
testMethod = getattr(self._testcase, self._testcase._testMethodName)
if (getattr(self._testcase.__class__, "__unittest_skip__", False) or
getattr(testMethod, "__unittest_skip__", False)):
# If the class or method was skipped.
skip_why = (getattr(self._testcase.__class__, '__unittest_skip_why__', '') or
getattr(testMethod, '__unittest_skip_why__', ''))
try:
self._testcase._addSkip(self, self._testcase, skip_why)
except TypeError: # PY2
self._testcase._addSkip(self, skip_why)
if self._handle_skip():
return
self._testcase.debug()

Expand Down
1 change: 1 addition & 0 deletions testing/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def test_false(self):
self.flush(child)

def test_pdb_unittest_skip(self, testdir):
"""Test for issue #2137"""
p1 = testdir.makepyfile("""
import unittest
@unittest.skipIf(True, 'Skipping also with pdb active')
Expand Down

0 comments on commit ad56cd8

Please sign in to comment.