a
    !f                     @   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rd dlmZ eddddZeedee ed dddZejedddZejdddeed dddZejdddeed dddZejdd eed d!d"d#Zejdd eed dd$d%Zejdd d&ed d'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 )Zaddinivalue_line)r    r   Q/var/www/html/python-backend/venv/lib/python3.9/site-packages/_pytest/warnings.pypytest_configure   s    r   z'Literal['config', 'collect', 'runtest'])NNN)r   whenitemr   c              	   c   s   |  d}| jjpg }tjdd}|dus0J tjsRtjdtd tjdt	d t
|| |du rhdn|j}|dur|jddD ]"}|jD ]}	tjt|	d	d
  qqdV  |D ]}
|jjt|
||ddd qW d   n1 s0    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   s.    


r,   )r   r   c                 C   s   | j }tt|| j| j| j| j}| jdurzddl	}W n t
yL   Y nP0 || j}|durd| }|d| 7 }n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msgr5   tbZformatted_tburlr   r   r   warning_record_to_strJ   s*    
r=   T)hookwrapperZtryfirst)r   r   c                 c   s>   t | j| jd| d d V  W d    n1 s00    Y  d S )NZruntestr   r(   r   r   )r,   r   r(   )r   r   r   r   pytest_runtest_protocolh   s    r@   )sessionr   c                 c   sB   | j }t||jdd d d V  W d    n1 s40    Y  d S )NZcollectr?   r   r,   hookrA   r   r   r   r   pytest_collectionp   s
    
rE   )r>   )terminalreporterr   c                 c   sB   | j }t||jdd d d V  W d    n1 s40    Y  d S Nr   r?   rB   )rF   r   r   r   r   pytest_terminal_summaryy   s
    
rH   c                 c   sB   | j }t||jdd d d V  W d    n1 s40    Y  d S rG   rB   rD   r   r   r   pytest_sessionfinish   s
    
rI   r   )early_configr   c                 c   s<   t | | jdd d d V  W d    n1 s.0    Y  d S rG   )r,   rC   )rJ   r   r   r   pytest_load_initial_conftests   s    
rK   ) r"   r    
contextlibr   typingr   r   r   ZpytestZ_pytest.configr   r   r   Z_pytest.mainr	   Z_pytest.nodesr
   Z_pytest.terminalr   Ztyping_extensionsr   r   r,   WarningMessager0   r=   Zhookimplr@   rE   rH   rI   rK   r   r   r   r   <module>   sH   -



