o
    #if                  
   @   s  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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 dlZde
ddfddZede
ded dee ded fddZdejdefddZejddddededeef fddZejddddededeef fddZejdd d!eded fd"d#Zejdd deded fd$d%Zejdd d&d'ded fd(d)ZdS )*    )contextmanagerN)	Generator)Literal)Optional)apply_warning_filters)Config)parse_warning_filter)Session)Item)TerminalReporterconfigreturnc                 C   s   |  dd d S )Nmarkerszfilterwarnings(warning): add a warning filter to the given test. see https://docs.pytest.org/en/stable/how-to/capture-warnings.html#pytest-mark-filterwarnings )addinivalue_line)r    r   I/var/www/html/corbot_env/lib/python3.10/site-packages/_pytest/warnings.pypytest_configure   s   r   when)r   collectruntestitem)NNNc                 c   s"   |  d}| jjpg }tjddu}|dusJ tjs*tjdtd tjdt	d t
|| |du r5dn|j}|durT|jddD ]}|jD ]}	tjt|	d	d
  qGqBzdV  W |D ]}
|jjt|
||ddd q[n|D ]}
|jjt|
||ddd qnw W d   dS 1 sw   Y  dS )zContext manager that catches warnings generated in the contained execution block.

    ``item`` can be None if we are not in the context of an item execution.

    Each warning captured triggers the ``pytest_warning_recorded`` hook.
    filterwarningsT)recordNalways)category )nameF)escape)warning_messagenodeidr   location)kwargs)getiniknown_args_namespacepythonwarningswarningscatch_warningssyswarnoptionsr   DeprecationWarningPendingDeprecationWarningr   r   iter_markersargsr   pytest_warning_recordedcall_historicdict)r   ihookr   r   config_filterscmdline_filterslogr   markargr   r   r   r   catch_warnings_for_item   sJ   



"r6   r   c                 C   s   | j }tt|| j| j| j| j}| jdurPzddl	}W n
 t
y'   Y |S w || j}|durBd| }|d| 7 }|S d}|d7 }|d| d7 }|S )	z.Convert a warnings.WarningMessage to a string.Nr   
z
Object allocated at:
zPhttps://docs.pytest.org/en/stable/how-to/capture-warnings.html#resource-warningszDEnable tracemalloc to get traceback where the object was allocated.
zSee z for more info.)messager%   formatwarningstrr   filenamelinenolinesourcetracemallocImportErrorget_object_tracebackjoinformat)r   warn_msgmsgr?   tbformatted_tburlr   r   r   warning_record_to_strL   s0   
rI   T)wrappertryfirstc                 c   s@    t | j| jd| d d V W  d    S 1 sw   Y  d S )Nr   r   r0   r   r   )r6   r   r0   )r   r   r   r   pytest_runtest_protocolj   s   $rM   sessionc                 c   D    | j }t||jdd d d V W  d    S 1 sw   Y  d S )Nr   rL   r   r6   hookrN   r   r   r   r   pytest_collectionr      
$rS   )rJ   terminalreporterc                 c   rO   Nr   rL   rP   )rU   r   r   r   r   pytest_terminal_summary{   s   
$rW   c                 c   rO   rV   rP   rR   r   r   r   pytest_sessionfinish   rT   rX   early_configr   c                 c   s>    t | | jdd d d V W  d    S 1 sw   Y  d S rV   )r6   rQ   )rY   r   r   r   pytest_load_initial_conftests   s   
$rZ   )
contextlibr   r'   typingr   r   r   r%   _pytest.configr   r   r   _pytest.mainr	   _pytest.nodesr
   _pytest.terminalr   pytestr   r6   WarningMessager:   rI   hookimplobjectrM   rS   rW   rX   rZ   r   r   r   r   <module>   sV   1



