o
    Zh                  
   @   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 )Zaddinivalue_line)r    r   G/var/www/html/lang_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)ZgetiniZknown_args_namespaceZpythonwarningswarningscatch_warningssyswarnoptionsr   DeprecationWarningPendingDeprecationWarningr   r   Ziter_markersargsr   Zpytest_warning_recordedZcall_historicdict)r   ihookr   r   Zconfig_filtersZcmdline_filterslogr   markargr   r   r   r   catch_warnings_for_item   sJ   



"r-   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   Zwarn_msgmsgr6   tbZformatted_tburlr   r   r   warning_record_to_strL   s0   
r>   T)wrapperZtryfirstc                 c   s@    t | j| jd| d d V W  d    S 1 sw   Y  d S )Nr   r   r)   r   r   )r-   r   r)   )r   r   r   r   pytest_runtest_protocolj   s   $rA   sessionc                 c   D    | j }t||jdd d d V W  d    S 1 sw   Y  d S )Nr   r@   r   r-   hookrB   r   r   r   r   pytest_collectionr      
$rG   )r?   terminalreporterc                 c   rC   Nr   r@   rD   )rI   r   r   r   r   pytest_terminal_summary{   s   
$rK   c                 c   rC   rJ   rD   rF   r   r   r   pytest_sessionfinish   rH   rL   early_configr   c                 c   s>    t | | jdd d d V W  d    S 1 sw   Y  d S rJ   )r-   rE   )rM   r   r   r   pytest_load_initial_conftests   s   
$rN   )
contextlibr   r#   typingr   r   r   r!   Z_pytest.configr   r   r   Z_pytest.mainr	   Z_pytest.nodesr
   Z_pytest.terminalr   Zpytestr   r-   WarningMessager1   r>   ZhookimplobjectrA   rG   rK   rL   rN   r   r   r   r   <module>   sV   1



