
    [Fik                         d dl mZ d dl mZ d dl mZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ d d	lZerd d
lmZ dZde	dd	fdZej&                  dedd	fd       Zdedd	fdZ G d d      Zy	)    )List)Optional)TYPE_CHECKING)nodes)Config)Parser)Session)
TestReportN)Cachezcache/stepwiseparserreturnc                     | j                  d      }|j                  dddddd       |j                  d	d
dddd       y )Ngeneralz--swz
--stepwise
store_trueFstepwisezBExit on test failure and continue from last failing test next time)actiondefaultdesthelpz	--sw-skipz--stepwise-skipstepwise_skipz_Ignore the first failing test but stop on the next failing test. Implicitly enables --stepwise.)getgroup	addoption)r   groups     b/var/www/html/BankruptcyAI-uat/bankruptcy-ai/venv/lib/python3.12/site-packages/_pytest/stepwise.pypytest_addoptionr      sZ    OOI&E	OOQ   
OO)      configc                     | j                   j                  rd| j                   _        | j                  d      r&| j                  j                  t        |       d       y y )NTr   stepwiseplugin)optionr   r   	getoptionpluginmanagerregisterStepwisePlugin)r   s    r   pytest_configurer%   (   sJ    }}""!%
#%%nV&<>NO $r   sessionc                     | j                   j                  d      sZ| j                   j                  J t        | j                   d      ry | j                   j                  j	                  t
        g        y y )Nr   workerinput)r   r!   cachehasattrsetSTEPWISE_CACHE_DIRr&   s    r   pytest_sessionfinishr.   1   s]    >>##J/~~##///7>>=1   !3R8 0r   c                       e Zd ZdeddfdZdeddfdZdedeej                     ddfdZ
d	eddfd
Zdee   fdZddZy)r$   r   r   Nc                     || _         d | _        d| _        |j                  J |j                  | _        | j                  j	                  t
        d       | _        |j                  d      | _        y )N r   )	r   r&   report_statusr)   getr,   
lastfailedr!   skip)selfr   s     r   __init__zStepwisePlugin.__init__=   s\    *.||'''"LL
)-8JD)Q **?;	r   r&   c                     || _         y )Nr-   )r6   r&   s     r   pytest_sessionstartz"StepwisePlugin.pytest_sessionstartF   s	    r   itemsc                    | j                   sd| _        y d }t        |      D ]"  \  }}|j                  | j                   k(  s |} n |d| _        y d| d| _        |d | }|d |= |j                  j                  |       y )Nz)no previously failed tests, not skipping.z/previously failed test not found, not skipping.z	skipping z already passed items.)r:   )r4   r2   	enumeratenodeidhookpytest_deselected)r6   r   r:   failed_indexindexitem
deselecteds          r   pytest_collection_modifyitemsz,StepwisePlugin.pytest_collection_modifyitemsI   s     !LD $U+ 	KE4{{doo-$	 !RD#,\N:P!QD}-Jm|m$KK))
);r   reportc                 H   |j                   re| j                  r(|j                  | j                  k(  rd | _        d| _        y |j                  | _        | j                  J d| j                  _        y |j                  dk(  r"|j                  | j                  k(  rd | _        y y y )NFz0Test failed, continuing from this test next run.call)failedr5   r=   r4   r&   
shouldstopwhen)r6   rE   s     r   pytest_runtest_logreportz'StepwisePlugin.pytest_runtest_logreporta   s    ==yy ==DOO3&*DO!	 #)--||///F ' {{f$==DOO3&*DO 4 %r   c                 v    | j                   j                  d      dk\  r| j                  rd| j                   S y )Nverboser   z
stepwise: )r   r!   r2   r6   s    r   pytest_report_collectionfinishz-StepwisePlugin.pytest_report_collectionfinishy   s8    ;;  +q0T5G5G 2 2344r   c                     t        | j                  d      ry | j                  j                  t        | j
                         y )Nr(   )r*   r   r)   r+   r,   r4   rN   s    r   r.   z#StepwisePlugin.pytest_sessionfinish~   s,    4;;. 

)4??;r   )r   N)__name__
__module____qualname__r   r7   r	   r9   r   r   ItemrD   r
   rK   r   strrO   r.    r   r   r$   r$   <   sv    <v <$ <7 t <<%)%**%5<	<0+z +d +0 
<r   r$   )typingr   r   r   _pytestr   _pytest.configr   _pytest.config.argparsingr   _pytest.mainr	   _pytest.reportsr
   pytest_pytest.cacheproviderr   r,   r   hookimplr%   r.   r$   rV   r   r   <module>r`      s         ! ,   &  +% V  * PV P P P9' 9d 9G< G<r   