o
    h                  
   @   s  d dl 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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 erPd dlmZ deddfddZeded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 fddZejd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eded fd%d&Zejdd!d'd(ded fd)d*ZdS )+    N)contextmanager)	Generator)Optional)TYPE_CHECKING)apply_warning_filters)Config)parse_warning_filter)Session)Item)TerminalReporter)Literal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   F/var/www/html/ai/venv/lib/python3.10/site-packages/_pytest/warnings.pypytest_configure   s   r   whenz'Literal['config', 'collect', 'runtest']item)NNNc              	   c   s    |  d}| jjpg }tjdd_}|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
  qGqBdV  |D ]}
|jjt|
||ddd qYW d   dS 1 stw   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   s6   


"r5   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_strJ   s0   
rH   T)hookwrappertryfirstc                 c   sB    t | j| jd| d d V  W d    d S 1 sw   Y  d S )Nruntestr   r/   r   r   )r5   r   r/   )r   r   r   r   pytest_runtest_protocolh   s   "rM   sessionc                 c   F    | j }t||jdd d d V  W d    d S 1 sw   Y  d S )NcollectrL   r   r5   hookrN   r   r   r   r   pytest_collectionp      
"rT   )rI   terminalreporterc                 c   rO   Nr   rL   rQ   )rV   r   r   r   r   pytest_terminal_summaryy   s   
"rX   c                 c   rO   rW   rQ   rS   r   r   r   pytest_sessionfinish   rU   rY   early_configr   c                 c   s@    t | | jdd d d V  W d    d S 1 sw   Y  d S rW   )r5   rR   )rZ   r   r   r   pytest_load_initial_conftests   s   
"r[   ) r&   r$   
contextlibr   typingr   r   r   pytest_pytest.configr   r   r   _pytest.mainr	   _pytest.nodesr
   _pytest.terminalr   typing_extensionsr   r   r5   WarningMessager9   rH   hookimplrM   rT   rX   rY   r[   r   r   r   r   <module>   sZ    -



