a
    *ñ»j	  ã                   @  sö   d dl mZ d dl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mZ d dlmZ d dlmZ erœd dlmZ dZdddœdd„Zdddœdd„Zdddœdd„ZejG dd„ dƒƒZG dd„ dƒZdS ) é    )ÚannotationsN)Údatetime)Ú	timedelta)ÚAny)ÚTYPE_CHECKING)Únodes)ÚCache)ÚConfig)ÚParser)ÚSession)Ú
TestReport)ÚSelfzcache/stepwiser
   ÚNone)ÚparserÚreturnc                 C  sP   |   d¡}|jddddddd� |jd	d
ddddd� |jddddddd� d S )NZ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.z
--sw-resetz--stepwise-resetÚstepwise_resetzWResets stepwise state, restarting the stepwise workflow. Implicitly enables --stepwise.)ZgetgroupZ	addoption)r   Úgroup© r   ú6E:\soccer\ml_env\Lib\site-packages\_pytest/stepwise.pyÚpytest_addoption   s2    
úú	úr   r	   ©Úconfigr   c                 C  s8   | j js| j jrd| j _|  d¡r4| j t| ƒd¡ d S )NTr   Zstepwiseplugin)Úoptionr   r   r   Ú	getoptionZpluginmanagerÚregisterÚStepwisePlugin)r   r   r   r   Úpytest_configure5   s    
r#   r   ©Úsessionr   c                 C  s0   | j  d¡s,| j jd usJ ‚t| j dƒr,d S d S )Nr   Úworkerinput)r   r    ÚcacheÚhasattr©r%   r   r   r   Úpytest_sessionfinish=   s    r*   c                   @  sX   e Zd ZU ded< ded< ded< eddœd	d
„ƒZeddœdd„ƒZddœdd„ZdS )ÚStepwiseCacheInfoz
str | NoneÚlast_failedz
int | NoneÚlast_test_countÚstrÚlast_cache_date_strr   ©r   c                 C  s   t  | j¡S ©N)r   Úfromisoformatr/   ©Úselfr   r   r   Úlast_cache_dateS   s    z!StepwiseCacheInfo.last_cache_dater   c                 C  s   | d d t  ¡  ¡ d�S )N)r,   r-   r/   )r   ÚnowÚ	isoformat)Úclsr   r   r   ÚemptyW   s
    
ýzStepwiseCacheInfo.emptyr   c                 C  s   t  ¡  ¡ | _d S r1   )r   r6   r7   r/   r3   r   r   r   Úupdate_date_to_now_   s    z$StepwiseCacheInfo.update_date_to_nowN)	Ú__name__Ú
__module__Ú__qualname__Ú__annotations__Úpropertyr5   Úclassmethodr9   r:   r   r   r   r   r+   F   s   
r+   c                   @  sx   e Zd Zdddœdd„Zddœdd	„Zd
ddœdd„Zddddœdd„Zdddœdd„Zddœdd„Zddœdd„Z	dS )r"   r	   r   r   c                 C  sN   || _ d | _g | _|jd us J ‚|j| _| d¡| _| d¡| _|  ¡ | _d S )Nr   r   )	r   r%   Úreport_statusr'   r    ÚskipÚresetÚ_load_cached_infoÚcached_info)r4   r   r   r   r   Ú__init__d   s    zStepwisePlugin.__init__r+   r0   c              
   C  s†   | j  td ¡}|r~zt|d |d |d ƒW S  ttfy| } z4t|ƒj› d|› �}| j 	d|› d�¡ W Y d }~n
d }~0 0 t 
¡ S )Nr,   r-   r/   z: z!error reading cache, discarding (ú))r'   ÚgetÚSTEPWISE_CACHE_DIRr+   ÚKeyErrorÚ	TypeErrorÚtyper;   rA   Úappendr9   )r4   Zcached_dictÚeÚerrorr   r   r   rD   n   s    ý*z StepwisePlugin._load_cached_infor   r$   c                 C  s
   || _ d S r1   r)   )r4   r%   r   r   r   Úpytest_sessionstart~   s    z"StepwisePlugin.pytest_sessionstartzlist[nodes.Item])r   Úitemsr   c           	      C  s.  | j j}t|ƒ| j _| jr2| j d¡ d | j _d S | j jsJ| j d¡ d S |d urˆ|t|ƒkrˆ| j dt|ƒ› d|› d�¡ d | j _d S d }t|ƒD ]\}}|j| j jkr”|} q´q”|d u rÊ| j d¡ n`t	 
¡ | j j }tt| ¡ ƒd�}| j d|› d	|› d
�¡ |d |… }|d |…= |jj|d� d S )Nzresetting state, not skipping.z)no previously failed tests, not skipping.z&test count changed, not skipping (now z tests, previously z).z/previously failed test not found, not skipping.)Úsecondsz	skipping z" already passed items (cache from z! ago, use --sw-reset to discard).)rQ   )rE   r-   ÚlenrC   rA   rM   r,   Ú	enumerateÚnodeidr   r6   r5   r   ÚintÚtotal_secondsÚhookZpytest_deselected)	r4   r   rQ   r-   Zfailed_indexÚindexÚitemZ	cache_ageZ
deselectedr   r   r   Úpytest_collection_modifyitems�   s<    ÿÿ
z,StepwisePlugin.pytest_collection_modifyitemsr   )Úreportr   c                 C  sp   |j rL| jr*|j| jjkr"d | j_d| _ql|j| j_| jd usBJ ‚d| j_n |jdkrl|j| jjkrld | j_d S )NFz0Test failed, continuing from this test next run.Úcall)ÚfailedrB   rU   rE   r,   r%   Z
shouldstopÚwhen)r4   r\   r   r   r   Úpytest_runtest_logreport®   s    
ÿ
z'StepwisePlugin.pytest_runtest_logreportzlist[str] | Nonec                 C  s(   | j  ¡ dkr$| jr$dd„ | jD ƒS d S )Nr   c                 S  s   g | ]}d |› �‘qS )z
stepwise: r   )Ú.0Úxr   r   r   Ú
<listcomp>È   ó    zAStepwisePlugin.pytest_report_collectionfinish.<locals>.<listcomp>)r   Zget_verbosityrA   r3   r   r   r   Úpytest_report_collectionfinishÆ   s    z-StepwisePlugin.pytest_report_collectionfinishc                 C  s4   t | jdƒrd S | j ¡  | j tt | j¡¡ d S )Nr&   )	r(   r   rE   r:   r'   ÚsetrI   ÚdataclassesÚasdictr3   r   r   r   r*   Ë   s    
z#StepwisePlugin.pytest_sessionfinishN)
r;   r<   r=   rF   rD   rP   r[   r`   re   r*   r   r   r   r   r"   c   s   
-r"   )Ú
__future__r   rg   r   r   Útypingr   r   Z_pytestr   Z_pytest.cacheproviderr   Z_pytest.configr	   Z_pytest.config.argparsingr
   Z_pytest.mainr   Z_pytest.reportsr   Ztyping_extensionsr   rI   r   r#   r*   Ú	dataclassr+   r"   r   r   r   r   Ú<module>   s(   	