Skip to content

Commit

Permalink
Merge pull request #2225 from mbyt/allow_skipping_unittests_with_pdb_…
Browse files Browse the repository at this point in the history
…active

Allow to skip unittests if --pdb active
  • Loading branch information
nicoddemus authored Feb 8, 2017
2 parents a4fb971 + 6a097aa commit 3d9c5cf
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 9 deletions.
20 changes: 13 additions & 7 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
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.

* Ignore exceptions raised from descriptors (e.g. properties) during Python test collection (`#2234`_).
Thanks to `@bluetech`_.

*

* Replace ``raise StopIteration`` usages in the code by simple ``returns`` to finish generators, in accordance to `PEP-479`_ (`#2160`_).
Thanks `@tgoodlet`_ for the report and `@nicoddemus`_ for the PR.

*

* Skipping plugin now also works with test items generated by custom collectors (`#2231`_).
Thanks to `@vidartf`_.

*

* Conditionless ``xfail`` markers no longer rely on the underlying test item
being an instance of ``PyobjMixin``, and can therefore apply to tests not
Expand All @@ -19,17 +26,16 @@

*

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

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

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

.. _PEP-479: https://www.python.org/dev/peps/pep-0479/

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

.. _@vidartf: https://github.com/vidartf
.. _PEP-479: https://www.python.org/dev/peps/pep-0479/


3.0.6 (2017-01-22)
Expand Down
22 changes: 20 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 @@ -152,14 +151,33 @@ 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)
if self._handle_skip():
return
self._testcase.debug()


def _prunetraceback(self, excinfo):
pytest.Function._prunetraceback(self, excinfo)
traceback = excinfo.traceback.filter(
Expand Down
15 changes: 15 additions & 0 deletions testing/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,21 @@ def test_false(self):
assert 'debug.me' in rest
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')
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 3d9c5cf

Please sign in to comment.