a
    !fc                     @   s   d dl Z 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m	Z	 d dlm
Z
 d dlZG dd	 d	Zed
 dddZejddded
 dddZejddded
 dddZejddded
 dddZdS )    N)TracebackType)Any)Callable)	Generator)Optional)Typec                   @   s`   e Zd ZdZddddZddddd	Zd dd
dZeee	  ee	 ee
 ddddZdS )catch_threading_exceptiona  Context manager catching threading.Thread exception using
    threading.excepthook.

    Storing exc_value using a custom hook can create a reference cycle. The
    reference cycle is broken explicitly when the context manager exits.

    Storing thread using a custom hook can resurrect it if it is set to an
    object which is being finalized. Exiting the context manager clears the
    stored object.

    Usage:
        with threading_helper.catch_threading_exception() as cm:
            # code spawning a thread which raises an exception
            ...
            # check the thread exception: use cm.args
            ...
        # cm.args attribute no longer exists at this point
        # (to break a reference cycle)
    Nreturnc                 C   s   d | _ d | _d S N)args	_old_hookself r   X/var/www/html/python-backend/venv/lib/python3.9/site-packages/_pytest/threadexception.py__init__$   s    z"catch_threading_exception.__init__zthreading.ExceptHookArgs)r   r
   c                 C   s
   || _ d S r   )r   )r   r   r   r   r   _hook(   s    zcatch_threading_exception._hookc                 C   s   t j| _| jt _| S r   )	threading
excepthookr   r   r   r   r   r   	__enter__+   s    z#catch_threading_exception.__enter__)exc_typeexc_valexc_tbr
   c                 C   s$   | j d usJ | j t_d | _ | `d S r   )r   r   r   r   )r   r   r   r   r   r   r   __exit__0   s    z"catch_threading_exception.__exit__)__name__
__module____qualname____doc__r   r   r   r   r   BaseExceptionr   r   r   r   r   r   r      s   
r   )NNNr	   c               	   c   s   t  v} d V  | jrn| jjd u r$dn| jjj}d| d}|dt| jj| jj| jj	7 }t
t| W d    n1 s0    Y  d S )Nz	<unknown>zException in thread z

 )r   r   threadnamejoin	tracebackformat_exceptionr   	exc_valueexc_tracebackwarningswarnpytestZ%PytestUnhandledThreadExceptionWarning)cmZthread_namemsgr   r   r   thread_exception_runtest_hook<   s    r-   T)hookwrapperZtrylastc                   c   s   t  E d H  d S r   r-   r   r   r   r   pytest_runtest_setupL   s    r0   )r.   Ztryfirstc                   c   s   t  E d H  d S r   r/   r   r   r   r   pytest_runtest_callQ   s    r1   c                   c   s   t  E d H  d S r   r/   r   r   r   r   pytest_runtest_teardownV   s    r2   )r   r$   r(   typesr   typingr   r   r   r   r   r*   r   r-   Zhookimplr0   r1   r2   r   r   r   r   <module>   s"   -