a
    /§»a’  ã                   @   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rxd d
lmZ dZe
ddœdd„Zejeddœdd„ƒZeddœ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 )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)ZgetgroupZ	addoption)r   Úgroup© r   úJ/home/yuhw/wc/pochoir/venv/lib/python3.9/site-packages/_pytest/stepwise.pyÚpytest_addoption   s"    
úúr   ©Úconfigr   c                 C   s    |   d¡r| j t| ƒd¡ d S )Nr   Zstepwiseplugin)Ú	getoptionZpluginmanagerÚregisterÚStepwisePlugin)r   r   r   r   Úpytest_configure&   s    
r   ©Úsessionr   c                 C   s0   | j  d¡s,| j jd usJ ‚| j j tg ¡ d S )Nr   )r   r   ÚcacheÚsetÚSTEPWISE_CACHE_DIR©r   r   r   r   Úpytest_sessionfinish-   s    r$   c                   @   st   e Zd Zeddœdd„Zeddœdd„Zeeej	 ddœd	d
„Z
eddœdd„Zee dœdd„Zddœdd„ZdS )r   Nr   c                 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__5   s    zStepwisePlugin.__init__r   c                 C   s
   || _ d S ©Nr#   )r*   r   r   r   r   Úpytest_sessionstart>   s    z"StepwisePlugin.pytest_sessionstart)r   Úitemsr   c                 C   s€   | j sd| _d S d }t|ƒD ]\}}|j| j kr|} q:q|d u rJd| _n2d|› 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.)r.   )r(   r&   Ú	enumerateÚnodeidÚhookZpytest_deselected)r*   r   r.   Zfailed_indexÚindexÚitemZ
deselectedr   r   r   Úpytest_collection_modifyitemsA   s    
z,StepwisePlugin.pytest_collection_modifyitems)Úreportr   c                 C   sf   |j rF| jr&|j| jkrd | _d| _qb|j| _| jd us<J ‚d| j_n|jdkrb|j| jkrbd | _d S )NFz0Test failed, continuing from this test next run.Úcall)Úfailedr)   r0   r(   r   Z
shouldstopÚwhen)r*   r5   r   r   r   Úpytest_runtest_logreportY   s    ÿ
z'StepwisePlugin.pytest_runtest_logreport)r   c                 C   s&   | j  d¡dkr"| jr"d| j› �S d S )NÚverboser   z
stepwise: )r   r   r&   ©r*   r   r   r   Úpytest_report_collectionfinishq   s    z-StepwisePlugin.pytest_report_collectionfinishc                 C   s   | j  t| j¡ d S r,   )r    r!   r"   r(   r;   r   r   r   r$   v   s    z#StepwisePlugin.pytest_sessionfinish)Ú__name__Ú
__module__Ú__qualname__r   r+   r   r-   r   r   ZItemr4   r	   r9   r   Ústrr<   r$   r   r   r   r   r   4   s   	
þr   )Útypingr   r   r   ZpytestZ_pytestr   Z_pytest.configr   Z_pytest.config.argparsingr   Z_pytest.mainr   Z_pytest.reportsr	   Z_pytest.cacheproviderr
   r"   r   Zhookimplr   r$   r   r   r   r   r   Ú<module>   s    