U
    42i[                     @  s\  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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ddddZedddddddZdddddZejdddddd d!d"Zejdddd#dd$d%d&Zejdd'd(dd)d*d+Zejdd'd#dd$d,d-Zejdd'ddd.d/d0ZdS )1    )annotations)contextmanagerN)	Generator)Literal)apply_warning_filters)Config)parse_warning_filter)Session)Item)TerminalReporterr   None)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   4/tmp/pip-unpacked-wheel-7n2p7kht/_pytest/warnings.pypytest_configure   s    r   z)Literal[('config', 'collect', 'runtest')]zItem | NonezGenerator[None])r   whenitemr   c                 c  s   |  d}| jjpg }tjdd}|dk	s0ttjsRtjdt	d tjdt
d t|| |dkrhdn|j}|dk	r|jddD ]"}|jD ]}	tjt|	d	d
  qqz
dV  W 5 |D ]}
|jjt|
||ddd qX W 5 Q R X 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AssertionError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   s0    



r-   zwarnings.WarningMessagestr)r   r   c                 C  s   | j }tt|| j| j| j| j}| jdk	rzddl	}W n t
k
rN   Y nPX || j}|dk	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    formatwarningr.   r   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_strM   s*    
r>   T)wrapperZtryfirstr
   zGenerator[None, object, object])r   r   c              
   c  s2   t | j| jd| d d V W  5 Q R  S Q R X d S )NZruntestr   r)   r   r   )r-   r   r)   )r   r   r   r   pytest_runtest_protocolk   s       rA   r	   )sessionr   c              
   c  s6   | j }t||jdd d d V W  5 Q R  S Q R X d S )NZcollectr@   r   r-   hookrB   r   r   r   r   pytest_collections   s       rF   )r?   r   )terminalreporterr   c              
   c  s6   | j }t||jdd d d V W  5 Q R  S Q R X d S Nr   r@   rC   )rG   r   r   r   r   pytest_terminal_summary|   s       rI   c              
   c  s6   | j }t||jdd d d V W  5 Q R  S Q R X d S rH   rC   rE   r   r   r   pytest_sessionfinish   s       rJ   )early_configr   c              
   c  s0   t | | jdd d d V W  5 Q R  S Q R X d S rH   )r-   rD   )rK   r   r   r   pytest_load_initial_conftests   s       rL   )
__future__r   
contextlibr   r#   typingr   r   r    Z_pytest.configr   r   r   Z_pytest.mainr	   Z_pytest.nodesr
   Z_pytest.terminalr   Zpytestr   r-   r>   ZhookimplrA   rF   rI   rJ   rL   r   r   r   r   <module>   s4   1



