
    ?g3                       S r SSKJr  SSKrSSKrSSKrSSKrSSKJr  SSKJ	r	  SSKJ
r
  SSKrSSKJr  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJ r   S!S jr!S"S jr"S#S jr# " S S5      r$ " S S5      r% " S S5      r&S$S jr'S$S jr(        S%S jr)S&S jr*S'S  jr+g)(z4Interactive debugging with PDB, the Python Debugger.    )annotationsN)Any)Callable)	Generator)outcomes)ExceptionInfo)CaptureManager)Config)ConftestImportFailure)hookimpl)PytestPluginManager)Parser)
UsageError)Node)
BaseReport)CallInfoc                     U R                  S5      u  pX4$ ! [         a   n[        R                  " U < S35      UeSnAff = f)z#Validate syntax of --pdbcls option.:z) is not in the format 'modname:classname'N)split
ValueErrorargparseArgumentTypeError)valuemodname	classnamees       3/usr/lib/python3/dist-packages/_pytest/debugging.py_validate_usepdb_clsr      sV    "[[-
 	  ((i@A
	s    
A=Ac                    U R                  S5      nUR                  SSSSS9  UR                  SSS	[        S
S9  UR                  SSSSS9  g )Ngeneralz--pdbusepdb
store_truezDStart the interactive Python debugger on errors or KeyboardInterrupt)destactionhelpz--pdbcls
usepdb_clszmodulename:classnamez{Specify a custom interactive Python debugger for use with --pdb.For example: --pdbcls=IPython.terminal.debugger:TerminalPdb)r#   metavartyper%   z--tracetracez(Immediately break when running each test)getgroup
_addoptionr   )parsergroups     r   pytest_addoptionr.   )   sw    OOI&E	S	   
&!F   
7	      c                "  ^ SS K mU R                  S5      (       a$  U R                  R                  [	        5       S5        U R                  S5      (       a$  U R                  R                  [        5       S5        [        R                  R                  TR                  [        R                  [        R                  45        [        R                  Tl	        U R                  [        l
        U [        l        SU4S jjnU R                  U5        g )Nr   r)   pdbtracer!   	pdbinvokec                 x   > [         R                  R                  5       u  T l        [         l        [         l        g N)	pytestPDB_savedpop	set_trace_pluginmanager_config)pdbs   r   finpytest_configure.<locals>.finR   s-    
   "		
M$r/   returnNone)r;   getvaluepluginmanagerregisterPdbTrace	PdbInvoker5   r6   appendr8   r9   r:   add_cleanup)configr<   r;   s     @r   pytest_configurerI   A   s    w%%hj*=x  %%ik;?		00)2C2CD ''CM%33II# sr/   c                      \ rS rSr% SrSrS\S'   SrS\S'   / rS\S	'   S
r	Sr
S\S'   \SS j5       r\SS j5       r\SS j5       r\S 5       r\SS j5       rSrg)r5   \   z'Pseudo PDB that defers to the real pdb.NzPytestPluginManager | Noner9   zConfig | Noner:   zKlist[tuple[Callable[..., None], PytestPluginManager | None, Config | None]]r6   r   z"tuple[type[Any], type[Any]] | None_wrapped_pdb_clsc                2    U(       a  UR                  5       $ g)NF)is_capturing)clscapmans     r   _is_capturingpytestPDB._is_capturingg   s    &&((r/   c                f   U R                   (       d  SS KnUR                  $ U R                   R                  S5      nU R                  (       a"  U R                  S   U:X  a  U R                  S   $ U(       aZ  Uu  pE [        U5        [        R                  U   nUR                  S5      n[        XgS   5      nUSS   H  n	[        X5      nM     OSS KnUR                  nU R                  X5      nX<4U l        U$ ! [         a*  n
SR                  XE45      n[        SU< SU
 35      U
eS n
A
ff = f)Nr   r&      .r   z--pdbcls: could not import z: )r:   r;   PdbrA   rL   
__import__sysmodulesr   getattr	Exceptionjoinr   _get_pdb_wrapper_class)rO   rP   r;   r&   r   r   modpartspdb_clspartexcr   wrapped_clss                r   _import_pdb_clspytestPDB._import_pdb_clsm   s'   {{ 77N[[)),7
C$8$8$;z$I''**!+G7#kk'* ",!#Qx0!!"ID%g4G & ggG00A *8  '!56 1%"SEBs   <AC< <
D0%D++D0c                4   ^ ^^ SS K m " UUU 4S jSU5      nU$ )Nr   c                  |   >^  \ rS rSr YrSrU U4S jrU UU4S jr\=rr	U U4S jr
\
r\
rU 4S jrU 4S jrSrU =r$ )	:pytestPDB._get_pdb_wrapper_class.<locals>.PytestPdbWrapper   Fc                z   > T=R                   S-  sl         [        TU ]	  U5      nT=R                   S-  sl         U$ )NrT   )_recursive_debugsuperdo_debugselfargret	__class__rO   s      r   rm   CpytestPDB._get_pdb_wrapper_class.<locals>.PytestPdbWrapper.do_debug   s9    $$)$g&s+$$)$
r/   c                T  > [         TU ]  U5      nTR                  S:X  a  TR                  c   eTR                  R                  TR                  5      nUR                  5         U R                  n[        R                  U5      nU(       aE  US:X  a  UR                  SS5        OUR                  SSU S35        Uc   eUR                  5         OUR                  SS5        TR                  c   eTR                  R                  R                  TR                  U S9  S	U l        U$ )
Nr   global>z#PDB continue (IO-capturing resumed)z'PDB continue (IO-capturing resumed for )zPDB continuerH   r;   T)rl   do_continuerk   r:   rH   create_terminal_writerline_pytest_capmanr5   rQ   sepresumer9   hookpytest_leave_pdb
_continued)	ro   rp   rq   twrP   	capturingrr   _pytestrO   s	         r   ry   FpytestPDB._get_pdb_wrapper_class.<locals>.PytestPdbWrapper.do_continue   s	   g)#.''1,;;222 >>s{{KBGGI!00F ) 7 7 ?I $0FF3(MNFF #"I)TU V  &111sN3))555""''88QU8V"&
r/   c                r   > [         TU ]  U5      nTR                  S:X  a  [        R                  " S5        U$ )zRaise Exit outcome when quit command is used in pdb.

This is a bit of a hack - it would be better if BdbQuit
could be handled, but this would require to wrap the
whole pytest run, and adjust the report etc.
r   Quitting debugger)rl   do_quitrk   r   exitrn   s      r   r   BpytestPDB._get_pdb_wrapper_class.<locals>.PytestPdbWrapper.do_quit   s3     goc*''1,MM"56
r/   c                   > [         TU ]  X5      nU(       d;  U R                  (       a*  U R                  (       a  U R                  R	                  SS9  U$ )z^Suspend on setup().

Needed after do_continue resumed, and entering another
breakpoint again.
Tin_)rl   setupr   r|   suspend_global_capture)ro   ftbrq   rr   s       r   r   @pytestPDB._get_pdb_wrapper_class.<locals>.PytestPdbWrapper.setup   sC     gmA*t **++BBtBL
r/   c                $  > [         TU ]  X5      u  p4Ucy  [        S[        U5      S-
  5      nU(       aZ  X4   S   R                  R                  SS5      (       a4  US-  nU(       a(  X4   S   R                  R                  SS5      (       a  M4  X44$ )Nr   rT   __tracebackhide__F)rl   	get_stackmaxlenf_localsget)ro   r   tstackirr   s        r   r   DpytestPDB._get_pdb_wrapper_class.<locals>.PytestPdbWrapper.get_stack   s     7,Q29As5zA~.A 4 4 8 89Le T TQ  4 4 8 89Le T Txr/   )r   )__name__
__module____qualname____firstlineno__r|   r   rm   ry   do_cdo_contr   do_qdo_exitr   r   __static_attributes____classcell__)rr   r   rP   rO   s   @r   PytestPdbWrapperrh      sC    #NJ4 )(D7 DG   r/   r   )_pytest.config)rO   r`   rP   r   r   s   ` ` @r   r]    pytestPDB._get_pdb_wrapper_class   s#    L	  L	 w L	 \  r/   c                    SSK nU R                  c  SnOU R                  R                  S5      nU(       a  UR                  SS9  U R                  (       a  UR
                  R                  U R                  5      nUR                  5         U R                  S:X  a  UR                  SS5      nUb  UR                  SU5        OdU R                  U5      nUS:X  a  UR                  SS	U S
35        O6U(       a  UR                  SS	U SU S35        OUR                  SS	U 35        U R                  U5      " S0 UD6n	U R                  (       a.  U R                  R                  R                  U R                  U	S9  U	$ )z4Initialize PDB debugging, dropping any IO capturing.r   NcapturemanagerTr   headerrv   ru   zPDB z (IO-capturing turned off)z (IO-capturing turned off for rw   rx    )r   r9   	getpluginsuspendr:   rH   rz   r{   rk   r7   r}   rQ   rd   r   pytest_enter_pdb)
rO   methodargskwargsr   rP   r   r   r   _pdbs
             r   	_init_pdbpytestPDB._init_pdb   sO    	%,0F''112BCFNNtN$;;66s{{CBGGI##q(Hd3%FF3' # 1 1& 9I H,sd6(2L$MN""6(*HSTU
 sd6(O4""6*4V4##44CKKT4Rr/   c                    [         R                  " 5       R                  nU R                  " S/UQ70 UD6nUR	                  U5        g)zBInvoke debugging via ``Pdb.set_trace``, dropping any IO capturing.r8   N)rX   	_getframef_backr   r8   )rO   r   r   framer   s        r   r8   pytestPDB.set_trace  s9     &&}}[:4:6:ur/   r   )rP   CaptureManager | Noner?   z
str | bool)rP   r   r>   )r   r   r   r   __doc__r9   __annotations__r:   r6   rk   rL   classmethodrQ   rd   r]   r   r8   r   r   r/   r   r5   r5   \   s    115N.5!G]! 	    ;?8? 
 $ $L Q  Q f $ $L  r/   r5   c                  8    \ rS rSr        SS jrSS jrSrg)rE   i  c                   UR                   R                  R                  S5      nU(       a_  UR                  SS9  UR	                  5       u  pV[
        R                  R                  U5        [
        R                  R                  U5        UR                  c   e[        UR                  R                  [        R                  5      (       d  [        XR                  U5        g g )Nr   Tr   )rH   rB   r   r   read_global_capturerX   stdoutwriteexcinfo
isinstancer   unittestSkipTest
_enter_pdb)ro   nodecallreportrP   outerrs          r   pytest_exception_interact#PdbInvoke.pytest_exception_interact  s     **445EF))d)3113HCJJS!JJS!||'''$,,,,h.?.?@@t\\62 Ar/   c                0    [        U5      n[        U5        g r4   )_postmortem_tracebackpost_mortem)ro   r   r   s      r   pytest_internalerrorPdbInvoke.pytest_internalerror&  s    "7+Br/   r   N)r   r   r   zCallInfo[Any]r   r   r?   r@   )r   ExceptionInfo[BaseException]r?   r@   )r   r   r   r   r   r   r   r   r/   r   rE   rE     s,    33 -37A3	3r/   rE   c                  0    \ rS rSr\" SS9SS j5       rSrg)rD   i+  T)wrapperc              #  (   #    [        U5        S v $ 7fr4   ) wrap_pytest_function_for_tracing)ro   
pyfuncitems     r   pytest_pyfunc_callPdbTrace.pytest_pyfunc_call,  s     (4s   r   N)r?   zGenerator[None, object, object])r   r   r   r   r   r   r   r   r/   r   rD   rD   +  s    d r/   rD   c                   ^^ [         R                  S5      mU R                  m[        R                  " T5      SUU4S jj5       nXl        g)zChange the Python function object of the given Function item by a
wrapper which actually enters pdb before calling the python function
itself, effectively leaving the user in the pdb prompt in the first
statement of the function.runcallc                 \   > [         R                  " T/U Q70 UD6nTR                  U5        g r4   )	functoolspartialr   )r   r   funcr   testfunctions      r   r   1wrap_pytest_function_for_tracing.<locals>.wrapper=  s)      ???Tr/   Nr>   )r5   r   objr   wraps)r   r   r   r   s     @@r   r   r   2  sB    
 y)D>>L
 __\" # Nr/   c                \    U R                   R                  S5      (       a  [        U 5        gg)z]Wrap the given pytestfunct item for tracing support if --trace was given in
the command line.r)   N)rH   rA   r   )r   s    r   &maybe_wrap_pytest_function_for_tracingr   E  s(     !!'**(4 +r/   c                X   U R                   R                  R                  S5      R                  nUR	                  5         U R                   R
                  R                  nSUR                  4SUR                  4SUR                  44 HK  u  pVXES4;   d  M  U(       d  M  UR                  SSU-   5        USS  S	:X  a  US S nUR	                  U5        MM     UR                  SS
5        UR                  U5        UR                  SS5        [        U5      nSUl        [        U5        U$ )Nterminalreporterr   stderrlogallrv   z	captured 
	tracebackzentering PDBT)rH   rB   r   _twr{   optionshowcapture	capstdout	capstderrcaplogr}   
toterminalr   	_pdbshownr   )r   r   repr   r   sectionnamecontentr   s           r   r   r   L  s    
	"	"	,	,-?	@	D	DBGGI++$$00K 
3==!	3==!	

!
 ..77FF3k12rs|t#!#2,GGG! FF3NN2FF3	w	'BCMOJr/   c                v   SSK Jn  [        U R                  U5      (       a  U R                  R                  S   $ [        U R                  [
        5      (       aC  U R                  R                  R                  c   eU R                  R                  R                  $ U R                  c   eU R                  S   $ )Nr   )UnexpectedException   )	doctestr   r   r   exc_infor   cause__traceback___excinfo)r   r   s     r   r   r   k  s    +'--!455 }}%%a((	GMM#8	9	9 }}""00<<<}}""000+++""r/   c                    [         R                  S5      nUR                  5         UR                  S U 5        UR                  (       a  [
        R                  " S5        g g )Nr   r   )r5   r   resetinteractionquittingr   r   )r   ps     r   r   r   |  sB    M*AGGIMM$zz)* r/   )r   strr?   ztuple[str, str])r,   r   r?   r@   )rH   r
   r?   r@   r>   )r   r   r   r   r   r   r?   r   )r   r   r?   types.TracebackType)r   r  r?   r@   ),r   
__future__r   r   r   rX   typestypingr   r   r   r   r   r   _pytest._coder   _pytest.capturer	   r   r
   r   r   r   _pytest.config.argparsingr   _pytest.config.exceptionsr   _pytest.nodesr   _pytest.reportsr   _pytest.runnerr   r   r.   rI   r5   rE   rD   r   r   r   r   r   r   r/   r   <module>r     s    ; "   
       ' * ! 0 # . , 0  & # 06x xv ( &5
5<F>#"+r/   