Skip to content

Commit 1584322

Browse files
authored
Merge pull request #4924 from blueyed/fix-pdbpp
Fix/harden some pdb tests
2 parents 612c378 + bdac9d3 commit 1584322

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

testing/test_pdb.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ def test_2():
457457
child.read()
458458
self.flush(child)
459459

460-
def test_pdb_interaction_doctest(self, testdir):
460+
def test_pdb_interaction_doctest(self, testdir, monkeypatch):
461461
p1 = testdir.makepyfile(
462462
"""
463463
import pytest
@@ -468,11 +468,18 @@ def function_1():
468468
'''
469469
"""
470470
)
471+
# Prevent ~/.pdbrc etc to output anything.
472+
monkeypatch.setenv("HOME", str(testdir))
473+
471474
child = testdir.spawn_pytest("--doctest-modules --pdb %s" % p1)
472475
child.expect("Pdb")
473-
child.sendline("i")
474-
child.expect("0")
476+
477+
assert "UNEXPECTED EXCEPTION: AssertionError()" in child.before.decode("utf8")
478+
479+
child.sendline("'i=%i.' % i")
475480
child.expect("Pdb")
481+
assert "\r\n'i=0.'\r\n" in child.before.decode("utf8")
482+
476483
child.sendeof()
477484
rest = child.read().decode("utf8")
478485
assert "1 failed" in rest
@@ -528,15 +535,13 @@ def do_debug(self, arg):
528535
import sys
529536
import types
530537
531-
newglobals = {
532-
'Pdb': self.__class__, # NOTE: different with pdb.Pdb
533-
'sys': sys,
534-
}
535538
if sys.version_info < (3, ):
536539
do_debug_func = pdb.Pdb.do_debug.im_func
537540
else:
538541
do_debug_func = pdb.Pdb.do_debug
539542
543+
newglobals = do_debug_func.__globals__.copy()
544+
newglobals['Pdb'] = self.__class__
540545
orig_do_debug = types.FunctionType(
541546
do_debug_func.__code__, newglobals,
542547
do_debug_func.__name__, do_debug_func.__defaults__,

0 commit comments

Comments
 (0)