U
    `»{jô  ã                   @  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œdd„Zdd
dœdd„Zdd
dœdd„ZG dd„ dƒZdS )é    )Úannotations)Únodes)ÚCache)ÚConfig)ÚParser)ÚSession)Ú
TestReportzcache/stepwiser   ÚNone)Ú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. Implicitly enables --stepwise.)ZgetgroupZ	addoption)r
   Úgroup© r   úO/var/www/html/bwave/python/venv/lib/python3.8/site-packages/_pytest/stepwise.pyÚpytest_addoption   s"    
úúr   r   ©Úconfigr   c                 C  s0   | j jrd| j _|  d¡r,| j t| ƒd¡ d S )NTr   Zstepwiseplugin)Úoptionr   r   Ú	getoptionZpluginmanagerÚregisterÚStepwisePlugin)r   r   r   r   Úpytest_configure#   s    
r   r   ©Úsessionr   c                 C  s@   | j  d¡s<| j jd k	st‚t| j dƒr,d S | j j tg ¡ d S )Nr   Úworkerinput)r   r   ÚcacheÚAssertionErrorÚhasattrÚsetÚSTEPWISE_CACHE_DIR©r   r   r   r   Úpytest_sessionfinish+   s
    r'   c                   @  sj   e Zd Zd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  sH   || _ d | _d| _|jd k	s t‚|j| _| j td ¡| _| d¡| _	d S )NÚ r   )
r   r   Úreport_statusr!   r"   Ú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_sessionstartzlist[nodes.Item])r   Úitemsr   c                 C  s€   | j sd| _d S d }t|ƒD ]\}}|j| j kr|} q:q|d k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.)r0   )r+   r)   Ú	enumerateÚnodeidÚhookZpytest_deselected)r-   r   r0   Zfailed_indexÚindexÚitemZ
deselectedr   r   r   Úpytest_collection_modifyitemsC   s    
z,StepwisePlugin.pytest_collection_modifyitemsr   )Úreportr   c                 C  sf   |j rF| jr&|j| jkrd | _d| _qb|j| _| jd k	s<t‚d| j_n|jdkrb|j| jkrbd | _d S )NFz0Test failed, continuing from this test next run.Úcall)Zfailedr,   r2   r+   r   r"   Z
shouldstopÚwhen)r-   r7   r   r   r   Úpytest_runtest_logreport[   s    ÿ
z'StepwisePlugin.pytest_runtest_logreportz
str | None)r   c                 C  s$   | j  ¡ dkr | jr d| j› �S d S )Nr   z
stepwise: )r   Z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+   r;   r   r   r   r'   x   s    z#StepwisePlugin.pytest_sessionfinishN)	Ú__name__Ú
__module__Ú__qualname__r.   r/   r6   r:   r<   r'   r   r   r   r   r   6   s   	r   N)Ú
__future__r   Z_pytestr   Z_pytest.cacheproviderr   Z_pytest.configr   Z_pytest.config.argparsingr   Z_pytest.mainr   Z_pytest.reportsr   r%   r   r   r'   r   r   r   r   r   Ú<module>   s   