Skip to content

Commit

Permalink
Allow to skip unittests if --pdb active
Browse files Browse the repository at this point in the history
closes #2137
  • Loading branch information
mbyt committed Jan 31, 2017
1 parent 0931fe2 commit d1c7250
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
3.0.7 (unreleased)
=======================

*
* Fix regression, pytest now skips unittest correctly if run with ``--pdb``
(`#2137`_). Thanks to `@gst`_ for the report and `@mbyt`_ for the PR.

*

*

*

.. _@gst: https://github.com/gst

.. _#2137: https://github.com/pytest-dev/pytest/issues/2137


3.0.6 (2017-01-22)
==================
Expand Down
14 changes: 12 additions & 2 deletions _pytest/unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ def collect(self):
yield TestCaseFunction('runTest', parent=self)



class TestCaseFunction(pytest.Function):
_excinfo = None

Expand Down Expand Up @@ -157,9 +156,20 @@ def runtest(self):
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)
return
self._testcase.debug()


def _prunetraceback(self, excinfo):
pytest.Function._prunetraceback(self, excinfo)
traceback = excinfo.traceback.filter(
Expand Down
14 changes: 14 additions & 0 deletions testing/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,20 @@ def test_false(self):
assert 'debug.me' in rest
self.flush(child)

def test_pdb_unittest_skip(self, testdir):
p1 = testdir.makepyfile("""
import unittest
@unittest.skipIf(True, 'Skipping also with pdb active')
class MyTestCase(unittest.TestCase):
def test_one(self):
assert 0
""")
child = testdir.spawn_pytest("-rs --pdb %s" % p1)
child.expect('Skipping also with pdb active')
child.expect('1 skipped in')
child.sendeof()
self.flush(child)

def test_pdb_interaction_capture(self, testdir):
p1 = testdir.makepyfile("""
def test_1():
Expand Down

0 comments on commit d1c7250

Please sign in to comment.