B
    ܇\                 @   s0   d dl Z dd Ze jdd ZG dd dZdS )    Nc             C   s4   |  d}|jdddddd |jddd	d
d d S )NZgeneralz--swz
--stepwise
store_truestepwisez?exit on test fail and continue from last failing test next time)actiondesthelpz--stepwise-skipstepwise_skipz?ignore the first failing test but stop on the next failing test)ZgetgroupZ	addoption)parsergroup r
   /lib/python3.7/site-packages/_pytest/stepwise.pypytest_addoption   s    
r   c             C   s   | j t| d d S )NZstepwiseplugin)ZpluginmanagerregisterStepwisePlugin)configr
   r
   r   pytest_configure   s    r   c               @   s<   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )r   c             C   s>   || _ |d| _d | _| jr:|jdd | _|d| _d S )Nr   zcache/stepwiser   )r   getvalueactivesessioncacheget
lastfailedskip)selfr   r
   r
   r   __init__   s    zStepwisePlugin.__init__c             C   s
   || _ d S )N)r   )r   r   r
   r
   r   pytest_sessionstart$   s    z"StepwisePlugin.pytest_sessionstartc             C   sv   | j r| jsd S g }d}x*|D ]"}|j| jkr6d}P q|| qW |sLg }x|D ]}|| qRW |jj|d d S )NFT)items)r   r   nodeidappendremovehookZpytest_deselected)r   r   r   r   Zalready_passedfounditemr
   r
   r   pytest_collection_modifyitems'   s    

z,StepwisePlugin.pytest_collection_modifyitemsc             C   s   | j r|jrd| j_d S )Nz4Error when collecting test, stopping test execution.)r   failedr   
shouldstop)r   reportr
   r
   r   pytest_collectreport@   s    z#StepwisePlugin.pytest_collectreportc             C   sl   | j rd|jkrd S |jrL| jr:|j| jkr2d | _d| _qh|j| _d| j_n|jdkrh|j| jkrhd | _d S )NZxfailFz0Test failed, continuing from this test next run.Zcall)	r   keywordsr#   r   r   r   r   r$   Zwhen)r   r%   r
   r
   r   pytest_runtest_logreportF   s    

z'StepwisePlugin.pytest_runtest_logreportc             C   s.   | j r| jjd| j n| jjdg  d S )Nzcache/stepwise)r   r   r   setr   )r   r   r
   r
   r   pytest_sessionfinisha   s    z#StepwisePlugin.pytest_sessionfinishN)	__name__
__module____qualname__r   r   r"   r&   r(   r*   r
   r
   r
   r   r      s   	r   )Zpytestr   Zhookimplr   r   r
   r
   r
   r   <module>   s   