Merge pull request #4854 from blueyed/pdb-skip
pdb: add option to skip `pdb.set_trace()`
This commit is contained in:
commit
e88aa957ae
|
@ -0,0 +1,5 @@
|
||||||
|
The ``--pdb-skip`` option can now be used to ignore calls to
|
||||||
|
``pdb.set_trace()`` (and ``pytest.set_trace()``).
|
||||||
|
|
||||||
|
This is meant to help while debugging, where you want to use e.g. ``--pdb`` or
|
||||||
|
``--trace`` only, or just run the tests again without any interruption.
|
|
@ -59,6 +59,13 @@ def pytest_addoption(parser):
|
||||||
action="store_true",
|
action="store_true",
|
||||||
help="Immediately break when running each test.",
|
help="Immediately break when running each test.",
|
||||||
)
|
)
|
||||||
|
group._addoption(
|
||||||
|
"--pdb-skip",
|
||||||
|
"--pdb-ignore-set_trace",
|
||||||
|
dest="pdb_ignore_set_trace",
|
||||||
|
action="store_true",
|
||||||
|
help="Ignore calls to pdb.set_trace().",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def pytest_configure(config):
|
def pytest_configure(config):
|
||||||
|
@ -209,6 +216,9 @@ class pytestPDB(object):
|
||||||
@classmethod
|
@classmethod
|
||||||
def set_trace(cls, *args, **kwargs):
|
def set_trace(cls, *args, **kwargs):
|
||||||
"""Invoke debugging via ``Pdb.set_trace``, dropping any IO capturing."""
|
"""Invoke debugging via ``Pdb.set_trace``, dropping any IO capturing."""
|
||||||
|
if pytestPDB._config: # Might not be available when called directly.
|
||||||
|
if pytestPDB._config.getoption("pdb_ignore_set_trace"):
|
||||||
|
return
|
||||||
frame = sys._getframe().f_back
|
frame = sys._getframe().f_back
|
||||||
_pdb = cls._init_pdb(*args, **kwargs)
|
_pdb = cls._init_pdb(*args, **kwargs)
|
||||||
_pdb.set_trace(frame)
|
_pdb.set_trace(frame)
|
||||||
|
|
|
@ -10,6 +10,7 @@ import sys
|
||||||
import _pytest._code
|
import _pytest._code
|
||||||
import pytest
|
import pytest
|
||||||
from _pytest.debugging import _validate_usepdb_cls
|
from _pytest.debugging import _validate_usepdb_cls
|
||||||
|
from _pytest.main import EXIT_NOTESTSCOLLECTED
|
||||||
|
|
||||||
try:
|
try:
|
||||||
breakpoint
|
breakpoint
|
||||||
|
@ -1121,3 +1122,16 @@ def test_pdb_suspends_fixture_capturing(testdir, fixture):
|
||||||
assert child.exitstatus == 0
|
assert child.exitstatus == 0
|
||||||
assert "= 1 passed in " in rest
|
assert "= 1 passed in " in rest
|
||||||
assert "> PDB continue (IO-capturing resumed for fixture %s) >" % (fixture) in rest
|
assert "> PDB continue (IO-capturing resumed for fixture %s) >" % (fixture) in rest
|
||||||
|
|
||||||
|
|
||||||
|
def test_pdb_skip_option(testdir):
|
||||||
|
p = testdir.makepyfile(
|
||||||
|
"""
|
||||||
|
print("before_set_trace")
|
||||||
|
__import__('pdb').set_trace()
|
||||||
|
print("after_set_trace")
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
result = testdir.runpytest_inprocess("--pdb-ignore-set_trace", "-s", p)
|
||||||
|
assert result.ret == EXIT_NOTESTSCOLLECTED
|
||||||
|
result.stdout.fnmatch_lines(["*before_set_trace*", "*after_set_trace*"])
|
||||||
|
|
Loading…
Reference in New Issue