o
    Ú­jj  ã                   @   sÊ   d dl mZ d dl mZ 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 er<d d
lmZ dZde
ddfdd„Zejdeddfdd„ƒZdeddfdd„ZG dd„ dƒZdS )é    )ÚList)ÚOptional)ÚTYPE_CHECKINGN)Únodes)ÚConfig)ÚParser)ÚSession)Ú
TestReport)ÚCachezcache/stepwiseÚparserÚreturnc                 C   s:   |   d¡}|jddddddd� |jd	d
ddddd� d S )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   Úgroup© r   úM/var/www/html/CropPilot/venv/lib/python3.10/site-packages/_pytest/stepwise.pyÚpytest_addoption   s"   
ú
úr   Úconfigc                 C   s4   | j jrd| j _|  d¡r| j t| ƒd¡ d S d S )NTr   Ústepwiseplugin)Úoptionr   r   Ú	getoptionÚpluginmanagerÚregisterÚStepwisePlugin)r   r   r   r   Úpytest_configure'   s
   
ÿr"   Úsessionc                 C   sD   | j  d¡s | j jd usJ ‚t| j dƒrd S | j j tg ¡ d S d S )Nr   Úworkerinput)r   r   ÚcacheÚhasattrÚsetÚSTEPWISE_CACHE_DIR©r#   r   r   r   Úpytest_sessionfinish0   s   ùr*   c                   @   sz   e Zd Zdeddfdd„Zdeddfdd„Zded	eej	 ddfd
d„Z
deddfdd„Zdee fdd„Zddd„ZdS )r!   r   r   Nc                 C   sH   || _ d | _d| _|jd usJ ‚|j| _| j td ¡| _| d¡| _d S )NÚ r   )	r   r#   Úreport_statusr%   Úgetr(   Ú
lastfailedr   Úskip)Úselfr   r   r   r   Ú__init__<   s   zStepwisePlugin.__init__r#   c                 C   s
   || _ d S )Nr)   )r0   r#   r   r   r   Úpytest_sessionstartE   s   
z"StepwisePlugin.pytest_sessionstartÚitemsc                 C   s‚   | j sd| _d S d }t|ƒD ]\}}|j| j kr|} nq|d u r&d| _d S d|› d�| _|d |… }|d |…= |jj|d� d S )Nz)no previously failed tests, not skipping.z/previously failed test not found, not skipping.z	skipping z already passed items.)r3   )r.   r,   Ú	enumerateÚnodeidÚhookÚpytest_deselected)r0   r   r3   Úfailed_indexÚindexÚitemÚ
deselectedr   r   r   Úpytest_collection_modifyitemsH   s   þ

z,StepwisePlugin.pytest_collection_modifyitemsÚreportc                 C   sr   |j r%| jr|j| jkrd | _d| _d S |j| _| jd usJ ‚d| j_d S |jdkr5|j| jkr7d | _d S d S d S )NFz0Test failed, continuing from this test next run.Úcall)Úfailedr/   r5   r.   r#   Ú
shouldstopÚwhen)r0   r=   r   r   r   Úpytest_runtest_logreport`   s   

ÿ

ýz'StepwisePlugin.pytest_runtest_logreportc                 C   s&   | j  d¡dkr| jrd| j› �S d S )NÚverboser   z
stepwise: )r   r   r,   ©r0   r   r   r   Úpytest_report_collectionfinishx   s   z-StepwisePlugin.pytest_report_collectionfinishc                 C   s$   t | jdƒrd S | j t| j¡ d S )Nr$   )r&   r   r%   r'   r(   r.   rD   r   r   r   r*   }   s   z#StepwisePlugin.pytest_sessionfinish)r   N)Ú__name__Ú
__module__Ú__qualname__r   r1   r   r2   r   r   ÚItemr<   r	   rB   r   ÚstrrE   r*   r   r   r   r   r!   ;   s    	ÿÿ
þr!   )Útypingr   r   r   ÚpytestÚ_pytestr   Ú_pytest.configr   Ú_pytest.config.argparsingr   Ú_pytest.mainr   Ú_pytest.reportsr	   Ú_pytest.cacheproviderr
   r(   r   Úhookimplr"   r*   r!   r   r   r   r   Ú<module>   s"    