o
    rh                     @  s   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ZdddZdddZdddZG dd dZdS )    )annotations)nodes)Cache)Config)Parser)Session)
TestReportzcache/stepwiseparserr   returnNonec                 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   N/var/www/html/alpaca_bot/venv/lib/python3.10/site-packages/_pytest/stepwise.pypytest_addoption   s"   

r   configr   c                 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!   sessionr   c                 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_sessionfinish+   s   r)   c                   @  sH   e Zd ZdddZdd	d
ZdddZdddZdddZdddZdS )r    r   r   r
   r   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__7   s   zStepwisePlugin.__init__r"   r   c                 C  s
   || _ d S )Nr(   )r/   r"   r   r   r   pytest_sessionstart@   s   
z"StepwisePlugin.pytest_sessionstartitemslist[nodes.Item]c                 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.)r2   )r-   r+   	enumeratenodeidhookpytest_deselected)r/   r   r2   failed_indexindexitem
deselectedr   r   r   pytest_collection_modifyitemsC   s   

z,StepwisePlugin.pytest_collection_modifyitemsreportr   c                 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)r/   r=   r   r   r   pytest_runtest_logreport[   s   



z'StepwisePlugin.pytest_runtest_logreport
str | Nonec                 C  s$   | j  dkr| jrd| j S d S )Nr   z
stepwise: )r   get_verbosityr+   r/   r   r   r   pytest_report_collectionfinishs   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-   rE   r   r   r   r)   x   s   z#StepwisePlugin.pytest_sessionfinishNr   r   r
   r   r"   r   r
   r   )r   r   r2   r3   r
   r   )r=   r   r
   r   )r
   rC   )r
   r   )	__name__
__module____qualname__r0   r1   r<   rB   rF   r)   r   r   r   r   r    6   s    

	


r    N)r	   r   r
   r   rG   rH   )
__future__r   _pytestr   _pytest.cacheproviderr   _pytest.configr   _pytest.config.argparsingr   _pytest.mainr   _pytest.reportsr   r'   r   r!   r)   r    r   r   r   r   <module>   s    


