@@ -457,7 +457,7 @@ def test_2():
457
457
child .read ()
458
458
self .flush (child )
459
459
460
- def test_pdb_interaction_doctest (self , testdir ):
460
+ def test_pdb_interaction_doctest (self , testdir , monkeypatch ):
461
461
p1 = testdir .makepyfile (
462
462
"""
463
463
import pytest
@@ -468,11 +468,18 @@ def function_1():
468
468
'''
469
469
"""
470
470
)
471
+ # Prevent ~/.pdbrc etc to output anything.
472
+ monkeypatch .setenv ("HOME" , str (testdir ))
473
+
471
474
child = testdir .spawn_pytest ("--doctest-modules --pdb %s" % p1 )
472
475
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" )
475
480
child .expect ("Pdb" )
481
+ assert "\r \n 'i=0.'\r \n " in child .before .decode ("utf8" )
482
+
476
483
child .sendeof ()
477
484
rest = child .read ().decode ("utf8" )
478
485
assert "1 failed" in rest
@@ -528,15 +535,13 @@ def do_debug(self, arg):
528
535
import sys
529
536
import types
530
537
531
- newglobals = {
532
- 'Pdb': self.__class__, # NOTE: different with pdb.Pdb
533
- 'sys': sys,
534
- }
535
538
if sys.version_info < (3, ):
536
539
do_debug_func = pdb.Pdb.do_debug.im_func
537
540
else:
538
541
do_debug_func = pdb.Pdb.do_debug
539
542
543
+ newglobals = do_debug_func.__globals__.copy()
544
+ newglobals['Pdb'] = self.__class__
540
545
orig_do_debug = types.FunctionType(
541
546
do_debug_func.__code__, newglobals,
542
547
do_debug_func.__name__, do_debug_func.__defaults__,
0 commit comments