a
    ܌xd\                     @   s  d Z ddlZddlZddlZddlZ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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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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+m,Z, ddl-m.Z. ddl/m0Z0 ddl/m1Z1 ddl/m2Z2 dd l/m3Z3 dd!l4m5Z5 dd"l6m7Z7 dd#l6m8Z8 dd$l9m:Z: dd%l9m;Z; dd&l<m=Z= dd'l<m>Z> dd(l<m?Z? er2dd)l@mAZA dd*lBmCZC d+ZDd,ZEd-ZFG d.d/ d/ejGZHe5dd0d1d2ZIe1dd3d4d5ZJe1eKd3d6d7ZLe3d8d9e=eeKeKeKf d:d;d<ZMejNG d=d> d>ZOe.G d?d@ d@ZPe(e1e=dAdBdCZQeKeKeReeK dDdEdFZSe1e=e(eeKeTf eKdGdHdIZUeee> eeeReKeeR eKf  dJdKdLZVdMdMdNdOdPZWdNZXeReKeeReKf dQdRdSZYeeK dTdUdVZZe[eKdWdXdYZ\e?eKd:dZd[Z]dS )\zsTerminal reporting of the full testing process.

This is a good source for looking at the various reporting hooks.
    N)Counter)partial)Path)Any)Callable)cast)ClassVar)Dict)	Generator)List)Mapping)Optional)Sequence)Set)TextIO)Tuple)TYPE_CHECKING)Union)nodes)timing)ExceptionInfo)ExceptionRepr)TerminalWriter)wcswidth)running_on_ci)final)_PluggyPlugin)Config)ExitCode)hookimpl)Parser)Item)Node)absolutepath)bestrelpath)
BaseReport)CollectReport)
TestReport)Literal)Sessiong      ?)failedpassedskipped
deselectedxfailedxpassedwarningserrorZfEc                       sh   e Zd ZdZd
ee eeeee dd fddZ	de
je
jeeee df ee dddd	Z  ZS )MoreQuietActionzA modified copy of the argparse count action which counts down and updates
    the legacy quiet attribute at the same time.

    Used to unify verbosity handling.
    NF)option_stringsdestdefaultrequiredhelpreturnc                    s   t  j||d|||d d S )Nr   )r3   r4   nargsr5   r6   r7   )super__init__)selfr3   r4   r5   r6   r7   	__class__ H/var/www/html/Ranjet/env/lib/python3.9/site-packages/_pytest/terminal.pyr;   T   s    zMoreQuietAction.__init__)parser	namespacevaluesoption_stringr8   c                 C   s6   t || jdd }t|| j| t |ddd |_d S )Nr      quiet)getattrr4   setattrrF   )r<   rA   rB   rC   rD   Z	new_countr?   r?   r@   __call__e   s    zMoreQuietAction.__call__)NFN)N)__name__
__module____qualname____doc__r   strobjectboolr   r;   argparseArgumentParser	Namespacer   rI   __classcell__r?   r?   r=   r@   r2   M   s(   
    r2   )rA   r8   c              	   C   s\  | j dddd}|jddddd	d
d |jdddddd |jdddddd |jddtdd	dd |jdd	tddd |jdddtddd |jd d!dd"dd#d$ |jd%d&dd'dd(d) |jd*d+d'd,d- |jd.d/dd0d1g d2d3d4 |jd5dd6g d7d8d9d: |jd;d<ddd=d> |jd?d@dd@d1g dAdBd4 |jdCdDdDdEgdFdG | jdHdIdJdK d S )LNzterminal reportingZ	ReportingZgeneral)afterz-vz	--verbosecountr   verbosezIncrease verbosity)actionr5   r4   r7   z--no-header
store_trueF	no_headerzDisable headerz--no-summary
no_summaryzDisable summaryz-qz--quietzDecrease verbosityz--verbosityzSet verbosity. Default: 0.)r4   typer5   r7   z-rstorereportcharscharsa  Show extra test summary info as specified by chars: (f)ailed, (E)rror, (s)kipped, (x)failed, (X)passed, (p)assed, (P)assed with output, (a)ll except passed (p/P), or (A)ll. (w)arnings are enabled by default (see --disable-warnings), 'N' can be used to reset the list. (default: 'fE').)rX   r4   r5   metavarr7   z--disable-warningsz--disable-pytest-warningsdisable_warningszDisable warnings summary)r5   r4   rX   r7   z-lz--showlocalsZ
showlocalsz/Show locals in tracebacks (disabled by default))rX   r4   r5   r7   z--no-showlocalsstore_falsezFHide locals in tracebacks (negate --showlocals passed through addopts))rX   r4   r7   z--tbstyletbstyleauto)re   longshortnolinenativez5Traceback print mode (auto/long/short/line/native/no))r`   rX   r4   r5   choicesr7   z--show-captureshowcapture)rh   stdoutstderrlogallrp   zOControls how captured stdout/stderr/log is shown on failed tests. Default: all.)rX   r4   rk   r5   r7   z--fulltracez--full-tracez,Don't cut any tracebacks (default is to cut))rX   r5   r7   z--colorcolor)yesrh   re   z#Color terminal output (yes/no/auto)z--code-highlightrr   rh   zSWhether code should be highlighted (only if --color is also enabled). Default: yes.)r5   rk   r7   console_output_stylezConsole output: "classic", or with additional progress information ("progress" (percentage) | "count" | "progress-even-when-capture-no" (forces progress even when capture=no)progress)r7   r5   )ZgetgroupZ
_addoptionr2   int_REPORTCHARS_DEFAULTZaddini)rA   groupr?   r?   r@   pytest_addoptionr   s    			rx   configr8   c                    sJ   t | tj | j d | jjs*| jjrF fdd}| jj	
d| d S )Nterminalreporterc                    s"   d tt|} d|  d S )N z[traceconfig] )joinmaprN   
write_line)tagsargsmsgreporterr?   r@   mywriter   s    z"pytest_configure.<locals>.mywriterzpytest:config)TerminalReportersysrm   pluginmanagerregisteroptiondebugtraceconfigtracerootZsetprocessor)rz   r   r?   r   r@   pytest_configure   s
    r   c                 C   s   | j j}ddh}d}|D ]N}||v r,| }|dkr:d}q|dkrHd}q|dkrVd}q||vr||7 }q| j jsd	|vrd	| }n| j jrd	|v r|d	d}|S )
NFS aZsxXEfAZPpsxXEfNw)r   r^   lowerra   replace)rz   r^   Zold_aliasesZ
reportoptscharr?   r?   r@   getreportopt   s&    

r   TZtrylastreportr8   c                 C   sH   d}| j rd}n
| jrd}| j}| jdv r:|dkr:d}d}||| fS )Nr   .s)collectsetupteardownr*   r1   E)r+   r,   outcomewhenupper)r   letterr   r?   r?   r@   pytest_report_teststatus  s    r   c                   @   sb   e Zd ZU dZeed< dZee ed< dZee	ee
f  ed< dZeed< eee dd	d
ZdS )WarningReportao  Simple structure to hold warnings information captured by ``pytest_warning_recorded``.

    :ivar str message:
        User friendly message about the warning.
    :ivar str|None nodeid:
        nodeid that generated the warning (see ``get_location``).
    :ivar tuple fslocation:
        File system location of the source of the warning (see ``get_location``).
    messageNnodeid
fslocationTcount_towards_summaryry   c                 C   s@   | j r| j S | jr<| j\}}t|jjt|}| d| S dS )zSReturn the more user-friendly information about the location of a warning, or None.:N)r   r   r$   invocation_paramsdirr#   )r<   rz   filenameZlinenumrelpathr?   r?   r@   get_location5  s    
zWarningReport.get_location)rJ   rK   rL   rM   rN   __annotations__r   r   r   r   ru   r   r   r   r   r?   r?   r?   r@   r   #  s   

r   c                   @   s   e Zd Zdeee ddddZddddZee	dd	d
Z
eedddZeedddZeedddZeedddZejee ddddZeedddZeedddZeeddddZdeedddd Zddd!d"Zd#d$eeedd%d&d'Zddd(d)Zeeef edd*d+d,Zeedd*d-d.Zdeee ee	 edd/d0d1Zdeeedd3d4d5Zeedd6d7d8Zee e! dd9d:d;Z"e#ed<d=d>Z$e%j&edd?d@dAZ'e(ddBdCdDZ)e e* ddEdFdGZ+ee,eee	 ef ddHdIdJZ-e.ddKdLdMZ/eeddNdOZ0eddPdQdRZ1eddSdTZ2dddUdVZ3ee	ddWdXZ4dddYdZZ5e6ddKd[d\Z7dedd]d^d_Z8e9d`dadbddcdddeZ:e eee e f  ddfdgdhZ;ee<e didjdkZ=dbddcdldmZ>e e* ddEdndoZ?e9d`dpdbee	e@f dqdrdsZAe9d`dpeBdt ddudvZCeDeE ddwdxdyZFdddzd{ZGddd|d}ZHeeee	 eed~ddZIdd ZJdd ZKedddZLddddZMddddZNee<e. dPddZOeddPddZPe.ddddZQddddZRddddZSeTddddZUddddZVddddZWe,ee<e f dddZXeedddZYddddZZe,e<e,ee[eef f  ef dddZ\ee<e! dddZ]e,e<e,ee[eef f  ef dddZ^e,e<e,ee[eef f  ef dddZ_dS )r   N)rz   filer8   c                 C   s   dd l }|| _d| _d | _d | _i | _d | _d | _|jj	| _
|d u rJtj}|j||| _| jj| _d | _t|| _| jj| _| | _t | _|  | _d | _d | _d | _d S Nr   )_pytest.configrz   _numcollected_session_showfspathstats_main_color_known_typesr   r   	startpathr   rm   Zcreate_terminal_writer_tw	fullwidth_screen_widthcurrentfspathr   r^   Z	hasmarkupisattyset_progress_nodeids_reported_determine_show_progress_info_show_progress_info_collect_report_last_write_already_displayed_warnings_keyboardinterrupt_memo)r<   rz   r   _pytestr?   r?   r@   r;   B  s,    





zTerminalReporter.__init__z#Literal['progress', 'count', False]r8   c                 C   sl   | j dddkr&| j ddkr&dS | j ddr8dS | j d}|dksT|dkrXdS |dkrddS dS d	S )
zRReturn whether we should display progress information based on the current config.capturerh   rs   zprogress-even-when-capture-noFZ	setupshowrt   rV   N)rz   	getoptiongetini)r<   cfgr?   r?   r@   r   \  s    
z.TerminalReporter._determine_show_progress_infoc                 C   s   | j jj}|S N)rz   r   rW   )r<   	verbosityr?   r?   r@   r   q  s    
zTerminalReporter.verbosityc                 C   s
   | j dkS r   r   r<   r?   r?   r@   
showheaderv  s    zTerminalReporter.showheaderc                 C   s   t | jjjS r   )rP   rz   r   rZ   r   r?   r?   r@   rZ   z  s    zTerminalReporter.no_headerc                 C   s   t | jjjS r   )rP   rz   r   r[   r   r?   r?   r@   r[   ~  s    zTerminalReporter.no_summaryc                 C   s   | j d u r| jdkS | j S r   )r   r   r   r?   r?   r@   
showfspath  s    

zTerminalReporter.showfspath)valuer8   c                 C   s
   || _ d S r   )r   )r<   r   r?   r?   r@   r     s    c                 C   s
   | j dkS r   r   r   r?   r?   r@   showlongtestinfo  s    z!TerminalReporter.showlongtestinfo)r   r8   c                 C   s   ddd ||}|| jv S )Nxr   )r.   r,   )getr^   )r<   r   r?   r?   r@   hasopt  s    zTerminalReporter.hasopt)r   markupr8   c                 K   s   | j j|dd  }| jd u s*|| jkrn| jd urB| jrB|   || _t| j|}| j	  | j
|d  | jj
|fddi| d S )N::r   r|   flushT)rz   rootpathsplitr   r   )_write_progress_information_filling_spacer$   r   r   ri   write)r<   r   resr   fspathZ	relfspathr?   r?   r@   write_fspath_result  s    
z$TerminalReporter.write_fspath_resultr   )prefixextrar8   c                 K   sH   | j |kr&| j  || _ | j| |rD| jj|fi | d| _ d S )N)r   r   ri   r   )r<   r   r   kwargsr?   r?   r@   write_ensure_prefix  s    

z$TerminalReporter.write_ensure_prefixc                 C   s   | j r| j  d | _ d S r   )r   r   ri   r   r?   r?   r@   ensure_newline  s    
zTerminalReporter.ensure_newlineF)r   )contentr   r   r8   c                K   s   | j j|fd|i| d S )Nr   )r   r   )r<   r   r   r   r?   r?   r@   r     s    zTerminalReporter.writec                 C   s   | j   d S r   )r   r   r   r?   r?   r@   r     s    zTerminalReporter.flush)ri   r   r8   c                 K   s6   t |tst|dd}|   | jj|fi | d S )Nr   )errors)
isinstancerN   r   r   ri   )r<   ri   r   r?   r?   r@   r     s    
zTerminalReporter.write_linec                 K   sZ   | dd}|r.| jjt| d }d| }nd}t|}| jjd| | fi | dS )a-  Rewinds the terminal cursor to the beginning and writes the given line.

        :param erase:
            If True, will also add spaces until the full terminal width to ensure
            previous lines are properly erased.

        The rest of the keyword arguments are markup instructions.
        eraseFrE   r|   r   N)popr   r   lenrN   r   )r<   ri   r   r   Z
fill_countfillr?   r?   r@   rewrite  s    	
zTerminalReporter.rewrite)septitler   r   r8   c                 K   s$   |    | jj|||fi | d S r   )r   r   r   )r<   r   r   r   r   r?   r?   r@   	write_sep  s    zTerminalReporter.write_sep=)r   r   kwr8   c                 K   s   | j j||fi | d S r   )r   r   )r<   r   r   r   r?   r?   r@   section  s    zTerminalReporter.section)r   r   r8   c                 K   s   | j j|fi | d S r   )r   ri   )r<   r   r   r?   r?   r@   ri     s    zTerminalReporter.line)categoryitemsr8   c                 C   s.   || j v}| j |g | |r*|   d S r   )r   
setdefaultextend_set_main_color)r<   r   r   Zset_main_colorr?   r?   r@   
_add_stats  s    
zTerminalReporter._add_stats)excreprr8   c                 C   s&   t |dD ]}| d|  qdS )N
zINTERNALERROR> T)rN   r   r   )r<   r  ri   r?   r?   r@   pytest_internalerror  s    z%TerminalReporter.pytest_internalerror)warning_messager   r8   c                 C   s@   ddl m} |j|jf}||}t|||d}| d|g d S )Nr   )warning_record_to_str)r   r   r   r0   )Z_pytest.warningsr  r   linenor   r   )r<   r  r   r  r   r   Zwarning_reportr?   r?   r@   pytest_warning_recorded  s    z(TerminalReporter.pytest_warning_recorded)pluginr8   c                 C   s"   | j jjrd| }| | d S )NzPLUGIN registered: )rz   r   r   r   )r<   r  r   r?   r?   r@   pytest_plugin_registered  s    

z)TerminalReporter.pytest_plugin_registered)r   r8   c                 C   s   |  d| d S )Nr-   )r   )r<   r   r?   r?   r@   pytest_deselected  s    z"TerminalReporter.pytest_deselected)r   locationr8   c                 C   sL   | j r.| j|g|R  }| |d |   n| jrH| |d |   d S )Nr   )r   _locationliner   r   r   r   )r<   r   r  ri   r?   r?   r@   pytest_runtest_logstart   s    
z(TerminalReporter.pytest_runtest_logstartr   c                 C   s4  d| _ |}| jjj|| jd}|\}}}t|ts8d }n|\}}| ||g |sZ|sZd S t|d}|d u rt|d}	|jr|	sddi}n8|jr|	rddi}n$|j	rddi}n|j
rddi}ni }| jdkr| jj|fi | nD| j|j | j|jg|jR  }
|s| j|
|fi | |j
s6t|drt|}| jjjd	k rx| jj| jj td
 d }td||}nd| d}|r|d ur| j| | jr(|   nv|   | jd|jjj   | jr| jj| ! d dd n| jd | jj|fi | | jd|
  d| _"| #  d S )NT)r   rz   nodewasxfailgreenyellowredr       [100%]rE   z ({})z ()z[%s]r|   )cyanr   )$Z
_tests_ranrz   hookr   r   tupler   hasattrr+   r*   r,   r   r   r   r   addr   r  r  r   _get_raw_skip_reasonr   rW   r   width_of_current_liner   _format_trimmedr   r   r   r  Zgatewayid!_get_progress_information_messager   r   )r<   r   repr   r   r   wordr   Zrunning_xdistZ	was_xfailri   reasonavailable_widthZformatted_reasonr?   r?   r@   pytest_runtest_logreport  sr    











z)TerminalReporter.pytest_runtest_logreportc                 C   s    | j d usJ t| j| j jkS r   )r   r   r   testscollectedr   r?   r?   r@   _is_last_itemP  s    zTerminalReporter._is_last_itemr   r8   c           	      C   s   | j s
J | jdkr| jr| jdkrD| j j}td| d| d}ntd}| j| | jrh|   nL| 	 \}}| j
}|| d | jk}|r|  }| jj|d fi |d	i d S )
Nr   rV    [/]r  rE   r  T)r   r   r   r%  r   r   r  r&  r   _get_main_color_width_of_current_liner   r  r   r   )	r<   r   Z	num_testsZprogress_length
main_color_r   Z	past_edger   r?   r?   r@   pytest_runtest_logfinishU  s    


z)TerminalReporter.pytest_runtest_logfinishc                 C   s   | j s
J | j j}| jdkrh|rV| j}dtt| d}d| d}|t||S d| d| dS |rd	t| jd
 | S dS d S )NrV   z{:zd}r(  z/{}]z [ z / z ]z	 [{:3d}%]d   r  )r   r%  r   r   r   rN   format)r<   	collectedrt   Zcounter_formatformat_stringr?   r?   r@   r  j  s    

z2TerminalReporter._get_progress_information_messagec                 C   sN   |   \}}|  }| j}| jj| d }| j||fddi|di d S )NrE   r   T)r+  r  r,  r   r   r   rjust)r<   rq   r.  r   r   r   r?   r?   r@   r   {  s
    z:TerminalReporter._write_progress_information_filling_spacec                 C   s   | j jS )z%Return the width of the current line.)r   r  r   r?   r?   r@   r,    s    z'TerminalReporter._width_of_current_linec                 C   sR   | j r0| jjjdkrN| jdddd t | _n| jjjdkrN| jdddd d S )Nr   zcollecting ... T)r   boldrE   )r   rz   r   rW   r   r   timer   r   r?   r?   r@   pytest_collection  s    z"TerminalReporter.pytest_collectionc                 C   s^   |j r| d|g n|jr*| d|g dd |jD }|  jt|7  _| jrZ|   d S )Nr1   r,   c                 S   s   g | ]}t |tr|qS r?   )r   r!   .0r   r?   r?   r@   
<listcomp>      z9TerminalReporter.pytest_collectreport.<locals>.<listcomp>)r*   r   r,   resultr   r   r   report_collect)r<   r   r   r?   r?   r@   pytest_collectreport  s    z%TerminalReporter.pytest_collectreport)r   r8   c                 C   s@  | j jjdk rd S |s@t }| jd ur:| j|t kr:d S || _t| j	dg }t| j	dg }t| j	dg }| j
| }|rdnd}|t| j
d | j
dkrd	nd
 7 }|r|d||dkrd
nd	f 7 }|r|d| 7 }|r|d| 7 }| j
|kr|d| 7 }| jr2| j|ddd |r<| d n
| | d S )Nr   r1   r,   r-   z
collected zcollecting z itemrE   r   r   z / %d error%sz / %d deselectedz / %d skippedz / %d selectedT)r5  r   r  )rz   r   rW   r   r6  r   REPORT_COLLECTING_RESOLUTIONr   r   r   r   rN   r   r   r   r   )r<   r   tr   r,   r-   selectedri   r?   r?   r@   r=    s>    
zTerminalReporter.report_collectTr   r)   )sessionr8   c                 C   s  || _ t | _| jsd S | jdddd t }| jsdt	j d| }t
t	dd }|rdtt|d d	 }|d
| d|d	  d7 }|dtjjtj7 }| jdks| jjjst
| jjdd r|dtt	j 7 }| | | jjj| j| jd}| | d S )Nr   ztest session startsTr5  z	platform z -- Python pypy_version_infor      z[pypy--r*  z, pytest-{}, pluggy-{}r   Zpastebinz -- )rz   
start_path)r   r   r6  _sessionstarttimer   r   platformpython_versionrZ   r   rG   r}   r~   rN   r1  r   _versionversionpluggy__version__r   rz   r   r   
executabler   r  pytest_report_headerr   _write_report_lines_from_hooks)r<   rB  Zverinfor   rD  linesr?   r?   r@   pytest_sessionstart  s6    


z$TerminalReporter.pytest_sessionstartrR  r8   c                 C   s<   t |D ].}t|tr"| | q|D ]}| | q&qd S r   )reversedr   rN   r   )r<   rR  Zline_or_linesri   r?   r?   r@   rQ    s
    
z/TerminalReporter._write_report_lines_from_hooksry   c                 C   s   d|j  g}|jr,|dt|j |j  |jtjjkrZ|d}|d	d
| |j }|r|dd
t|  |S )Nz	rootdir: zconfigfile: 	testpathsztestpaths: {}, zplugins: %s)r   Zinipathappendr$   Zargs_sourcer   Z
ArgsSourceZ	TESTPATHSr   r1  r}   r   Zlist_plugin_distinfo_plugin_nameversions)r<   rz   r<  rV  
plugininfor?   r?   r@   rP    s    

z%TerminalReporter.pytest_report_headerc                 C   s   |  d | jjj| j| j|jd}| | | jdr|jrf| jjj	dkrZ| j
d | |j | jd}|r| j
dd |D ]}|| j
 qd S )	NT)rz   rG  r   collectonlyr   r*   !zcollection failures)r=  rz   r  Zpytest_report_collectionfinishr   r   rQ  r   r   rW   r   ri   _printcollecteditemsr   r   r   
toterminal)r<   rB  rR  r*   r   r?   r?   r@   pytest_collection_finish  s"    

z)TerminalReporter.pytest_collection_finishc              	   C   s^  | j jjdk rv| j jjdk rZtdd |D }t| D ]\}}| jd||f  q:n|D ]}| j|j q^d S g }d}|D ]}|	 dd  }|r||d t
| krq|  q|t
|d  D ]}	||	 t
|d d }| j| |	  | j jjdkrt|	d	d }
|
r&t|
nd }|r| D ]}| jd
|d | q6qqd S )Nr   r\  c                 s   s    | ]}|j d dd V  qdS r   rE   r   N)r   r   )r9  itemr?   r?   r@   	<genexpr>  r;  z8TerminalReporter._printcollecteditems.<locals>.<genexpr>z%s: %dr   rE     objz{}{})rz   r   rW   r   sortedr   r   ri   r   Z	listchainr   r   rX  rG   inspectgetdoc
splitlinesr1  )r<   r   countsnamerV   rb  stackindentZneeded_collectorscolre  docri   r?   r?   r@   r^  
  s4    

z%TerminalReporter._printcollecteditems)Zhookwrapper)rB  
exitstatusc                 c   s   d V }|   | jd tjtjtjtjtjf}||v rV| j	sV| j
jj| || j
d |jrr| jdt|jdd |tjkr|   d | _n|jr| jdt|jdd |   d S )Nr   )r{   rp  rz   r]  T)r  )Z
get_resultr   ri   r   OKZTESTS_FAILEDZINTERRUPTEDZUSAGE_ERRORZNO_TESTS_COLLECTEDr[   rz   r  pytest_terminal_summaryZ
shouldfailr   rN   _report_keyboardinterruptr   Z
shouldstopsummary_stats)r<   rB  rp  r   Zsummary_exit_codesr?   r?   r@   pytest_sessionfinish'  s*    
z%TerminalReporter.pytest_sessionfinish)NNNc                 c   s:   |    |   |   |   d V  |   |   d S r   )summary_errorssummary_failuressummary_warningssummary_passesshort_test_summaryr   r?   r?   r@   rr  B  s    z(TerminalReporter.pytest_terminal_summary)excinfor8   c                 C   s   |j dd| _d S )NT)Zfuncargs)Zgetreprr   )r<   r{  r?   r?   r@   pytest_keyboard_interruptM  s    z*TerminalReporter.pytest_keyboard_interruptc                 C   s   | j d ur|   d S r   )r   rs  r   r?   r?   r@   pytest_unconfigureP  s    
z#TerminalReporter.pytest_unconfigurec                 C   sv   | j }|d usJ |jd us J |jj}| d| d|v rr| jjjrT|| j n|j| j | jj	ddd d S )Nr]  KeyboardInterruptz@(to show a full traceback on KeyboardInterrupt use --full-trace)T)r  )
r   	reprcrashr   r   rz   r   Z	fulltracer_  r   ri   )r<   r  r   r?   r?   r@   rs  T  s    
z*TerminalReporter._report_keyboardinterrupt)r   r   r  domainr8   c                    sn   t t d fdd}|rb||}jdkrf|dd |dtjkrf|dtjt| 7 }nd	}|d
 S )Nr'  c                    s\   j | } rX| rX|d t   } d}|d dd|d< |d|7 }|S )N[r   r   r   )rz   cwd_relative_nodeidendswithr   r   r   r}   )r   ri   rC   r  r<   r?   r@   mkrelg  s    
z-TerminalReporter._locationline.<locals>.mkrelr  r   r   \z <- z
[location]r|   )	rN   r   r   r   r   ZSEPr$   r   r   )r<   r   r   r  r  r  r   r?   r  r@   r  d  s    
zTerminalReporter._locationlinec                 C   s   |j }|r|S dS )Nztest session)	head_line)r<   r   r  r?   r?   r@   _getfailureheadline{  s    z$TerminalReporter._getfailureheadlinec                 C   sV   zt |jjW S  tyP   zt |jd d W  Y S  tyJ   Y Y dS 0 Y n0 d S )N2   r   )rN   longreprr  AttributeError)r<   r   r?   r?   r@   _getcrashline  s    zTerminalReporter._getcrashline)rk  c                 C   s   dd | j |dD S )Nc                 S   s   g | ]}t |d s|qS )Z	_pdbshown)r  r8  r?   r?   r@   r:    r;  z/TerminalReporter.getreports.<locals>.<listcomp>r?   r   r   )r<   rk  r?   r?   r@   
getreports  s    zTerminalReporter.getreportsc                    s*    dr& jd}|s d S  jd u}|r>| jd  }n|}t| _|sTd S i }|D ]}||jg | q\tt	 t
d fdd}|rdnd} jd|d	d
d | D ]d\}}	||	}
|
r j|
 | }ddd |D }| }n| } j|  j  q jd d S )Nr   r0   )reportsr8   c                    sn   g }| D ]}|  j}|r|| qt|dk rDdtt|S tdd |D }ddd | D S )N
   r  c                 s   s"   | ]}t |d dd V  qdS ra  )rN   r   )r9  locr?   r?   r@   rc    s   zWTerminalReporter.summary_warnings.<locals>.collapsed_location_report.<locals>.<genexpr>c                 s   s,   | ]$\}}d  |||dkrdndV  qdS )z{}: {} warning{}rE   r   r   N)r1  )r9  kvr?   r?   r@   rc    s   )	r   rz   rX  r   r}   r~   rN   r   r   )r  	locationsr   r  Zcounts_by_filenamer   r?   r@   collapsed_location_report  s    
zDTerminalReporter.summary_warnings.<locals>.collapsed_location_reportzwarnings summary (final)zwarnings summaryr   TF)r  r5  r  c                 s   s   | ]}d | V  qdS )rd  Nr?   r8  r?   r?   r@   rc    r;  z4TerminalReporter.summary_warnings.<locals>.<genexpr>zG-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html)r   r   r   r   r   r   r   rX  r   r   rN   r   r   r   ri   ri  r}   rstrip)r<   Zall_warningsr   Zwarning_reportsZreports_grouped_by_messagewrr  r   r   Zmessage_reportsZmaybe_locationrR  Zindentedr?   r   r@   rx    s<    


z!TerminalReporter.summary_warningsc                 C   s|   | j jjdkrx| drx| d}|s*d S | dd |D ]<}|jrj| |}| jd|ddd | | | 	|j
 q:d S )	Nrh   Pr+   r   ZPASSESr.  T)r  r5  )rz   r   rd   r   r  r   sectionsr  _outrep_summary_handle_teardown_sectionsr   r<   r  r   r   r?   r?   r@   ry    s    



zTerminalReporter.summary_passesc                    s   |  d} fdd|D S )Nr   c                    s$   g | ]}|j d kr|j kr|qS )r   )r   r   )r9  r   r   r?   r@   r:    s   z:TerminalReporter._get_teardown_reports.<locals>.<listcomp>)r  )r<   r   r  r?   r  r@   _get_teardown_reports  s    

z&TerminalReporter._get_teardown_reportsc                 C   s   |  |D ]}| | q
d S r   )r  print_teardown_sections)r<   r   r   r?   r?   r@   r    s    z*TerminalReporter._handle_teardown_sections)r   r8   c                 C   sz   | j jj}|dkrd S |jD ]X\}}|dkr6||vr6qd|v r| jd| |dd  dkrh|d d }| j| qd S )Nrh   rp   r   rF  r\  r  )rz   r   rl   r  r   r   ri   r<   r   rl   Zsecnamer   r?   r?   r@   r    s    
z(TerminalReporter.print_teardown_sectionsc                 C   s   | j jjdkr| d}|s d S | dd | j jjdkrZ|D ]}| |}| | q>n<|D ]6}| |}| jd|ddd | | | 	|j
 q^d S )	Nrh   r*   r   ZFAILURESri   r.  Tr  r5  )rz   r   rd   r  r   r  r   r  r  r  r   )r<   r  r   ri   r   r?   r?   r@   rw    s    



z!TerminalReporter.summary_failuresc                 C   s   | j jjdkr| d}|s d S | dd | jd D ]P}| |}|jdkrXd| }nd|j d| }| jd	|d
d
d | | q6d S )Nrh   r1   r   ZERRORSr   zERROR collecting z	ERROR at z of r.  Tr  )	rz   r   rd   r  r   r   r  r   r  r  r?   r?   r@   rv    s    



zTerminalReporter.summary_errorsc                 C   s~   | | j | jjj}|dkr"d S |jD ]P\}}|dkrB||vrBq(| jd| |dd  dkrl|d d }| j| q(d S )Nrh   rp   rF  r\  r  )r_  r   rz   r   rl   r  r   ri   r  r?   r?   r@   r    s    
z TerminalReporter._outrep_summaryc                 C   sT  | j dk rd S t | j }|  \}}g }| j dk}|rB| jj}|D ]>\}}| jj|fi |}	|rz|t|	t| 7 }|	|	 qFd
|}
|di}dt| }| jj|fi |}|r|t|t| 7 }|
|7 }
|r| jjdi |}|dr
|d d }|t|7 }|
|7 }
|r>| jd	|
fd
|i| n| j|
fi | d S )Nr\  r   rW  Tz in r   z[0mr   r   )r   )r   r   r6  rH  build_summary_stats_liner   r   r   r   rX  r}   format_session_durationr  r   r   )r<   Zsession_durationpartsr-  Z
line_partsZdisplay_sepr   textr   Zwith_markupr   Zmain_markupdurationZduration_with_markupZmarkup_for_end_sepr?   r?   r@   rt    s:    


zTerminalReporter.summary_statsc           
   	      s    j s
d S tt td d fdd}tt d d fdd}tt d d fdd}tt d d fd	d
}||t|dd|t|ddt|ddd}g } j D ]}||}|r|| q|r jddddd |D ]}	 |	 qd S )N)rR  statr8   c                   sT    j |g }|sd S  j}|D ].}t|t}t|| j|di}| | q d S )NT)r   r   rz   _color_for_type_color_for_type_default _get_line_with_reprcrash_messager   rX  )rR  r  r*   rz   r   rq   ri   r   r?   r@   show_simpleC  s    z8TerminalReporter.short_test_summary.<locals>.show_simplerT  c                    s    j dg }|D ]n}| j} jj|fi td di}t j j|}| d| }|j}|rv|dt	| 7 }| 
| qd S )Nr.   r0   Tr|    - )r   r   _get_verbose_wordrz   r   r   r  _get_node_id_with_markupr  rN   rX  )rR  r.   r   verbose_wordmarkup_wordr   ri   r"  r   r?   r@   show_xfailedO  s    
z9TerminalReporter.short_test_summary.<locals>.show_xfailedc                    st    j dg }|D ]\}| j} jj|fi td di}t j j|}|j}| 	| d| d|  qd S )Nr/   r0   Tr|   )
r   r   r  rz   r   r   r  r  r  rX  )rR  r/   r   r  r  r   r"  r   r?   r@   show_xpassed^  s    
z9TerminalReporter.short_test_summary.<locals>.show_xpassedc           
   	      s    j dg }|rt j|ng }|s*d S |d  j} jj|fi td di}d}|D ]^\}}}}	|		|r|	t
|d  }	|d ur| d|||||	f  q^| d||||	f  q^d S )Nr,   r   r0   T	Skipped: z%s [%d] %s:%d: %sz%s [%d] %s: %s)r   r   _folded_skipsr   r  rz   r   r   r  
startswithr   rX  )
rR  r,   Zfskipsr  r  r   numr   r  r"  r   r?   r@   show_skippedi  s&    

z9TerminalReporter.short_test_summary.<locals>.show_skippedr*   )r  r+   r1   )r   Xfr   pr   r   zshort test summary infoT)r  r5  )r^   r   rN   r   r   r   r   )
r<   r  r  r  r  ZREPORTCHAR_ACTIONSrR  r   rX   ri   r?   r   r@   rz  ?  s,    


	


z#TerminalReporter.short_test_summaryc                 C   sB   | j d u s| jd u s| jr6|   | j s,J | js6J | j | jfS r   )r   r   r&  r   r   r?   r?   r@   r+    s
    

z TerminalReporter._get_main_color)unknown_type_seenr8   c                 C   sR   | j }d|v sd|v rd}n2d|v s0d|v s0|r6d}nd|v sD| jsJd}nd}|S )	Nr*   r1   r  r0   r/   r  r+   r  )r   r&  )r<   r  r   r-  r?   r?   r@   _determine_main_color  s    z&TerminalReporter._determine_main_colorc                 C   sT   g }| j  D ]"}|r|tvr||vr|| qtt| | _| t|| _d S r   )	r   keysKNOWN_TYPESrX  listr   r  rP   r   )r<   Zunknown_typesZ
found_typer?   r?   r@   r     s    z TerminalReporter._set_main_colorc                 C   s    | j dr|  S |  S dS )a  
        Build the parts used in the last summary stats line.

        The summary stats line is the line shown at the end, "=== 12 passed, 2 errors in Xs===".

        This function builds a list of the "parts" that make up for the text in that line, in
        the example above it would be:

            [
                ("12 passed", {"green": True}),
                ("2 errors", {"red": True}
            ]

        That last dict for each line is a "markup dictionary", used by TerminalWriter to
        color output.

        The final color of the line is also determined by this function, and is the second
        element of the returned tuple.
        r[  N)rz   r   &_build_collect_only_summary_stats_line _build_normal_summary_stats_liner   r?   r?   r@   r    s    z)TerminalReporter.build_summary_stats_line)keyr8   c                 C   s   | j |g }dd |D S )zRGet test/collection reports for the given status key, such as `passed` or `error`.c                 S   s   g | ]}t |d dr|qS )r   T)rG   r8  r?   r?   r@   r:    r;  z<TerminalReporter._get_reports_to_display.<locals>.<listcomp>r  )r<   r  r  r?   r?   r@   _get_reports_to_display  s    z(TerminalReporter._get_reports_to_displayc           	      C   s~   |   \}}g }|D ]N}| |}|rt|}t|t}|dd||ki}|dt|| |f q|svdtdifg}||fS )NTr5  %d %szno tests ran)r+  r  r   r  r   r  rX  	pluralize)	r<   r-  Zknown_typesr  r  r  rV   rq   r   r?   r?   r@   r    s    
z1TerminalReporter._build_normal_summary_stats_linec                 C   s   t | d}t | d}| jdkr:dddifg}d}n|dkrfd}dt| jd	 }||difg}nT| j|k}|rd}d
| d}n&d}| j| }| d| j d| d}||difg}|rtd }|dt|d |difg7 }||fS )Nr-   r1   r   zno tests collectedr  Tr  z%d %s collectedtestzno tests collected (z deselected)r)  z tests collected (r  )r   r  r   r  r  )r<   r-   r   r  r-  Zcollected_outputZall_tests_were_deselectedrA  r?   r?   r@   r    s*    


z7TerminalReporter._build_collect_only_summary_stats_line)N)r   )NN)r   )F)`rJ   rK   rL   r   r   r   r;   r   propertyru   r   rP   r   rZ   r[   r   setterr   rN   r   r   r   r   r   r   r   bytesr   r   r   r   ri   r   r   r   r   r  r0   WarningMessager  r   r	  r!   r
  r   r  r'   r$  r&  r/  r  r   r,  r7  r&   r>  r=  r   rS  rQ  r   rP  r`  r^  r   ru  r
   rr  r   BaseExceptionr|  r}  rs  r  r  r  r  rx  ry  r  r  r  rw  rv  r%   r  rt  rz  r+  r  r   r	   r  r  r  r  r?   r?   r?   r@   r   @  s   	  
C
%

6%R	*r   )twrz   r   c                 C   sF   | |j}|d^}}|r>| jd|dd}|d | S |S d S )Nr   TrC  )r  r   r   r   r}   )r  rz   r   r   pathr  Zparts_markupr?   r?   r@   r    s    r  )r1  r   r#  r8   c                 C   s   | d}|dkr|d| }d}t| d}|t| |krDdS |t| |kr|t|8 }|d| }|t| |kr|dd }ql||7 }| |S )zFormat msg into format, ellipsizing it if doesn't fit in available_width.

    Returns None if even the ellipsis can't fit.
    r  r\  Nz...r   )findr   r1  r   )r1  r   r#  iellipsisZformat_widthr?   r?   r@   r  	  s    
r  )rz   r   r  word_markupr8   c                 C   s   | | }|j|fi |}t|| |}| d| }t|}z|jjj}	W n ty^   Y n:0 t s~|j	| }
t
d|	|
}	n
d|	 }	|	dur||	7 }|S )z?Get summary line for a report, trying to add reprcrash message.r|   z - {}r  N)r  r   r  r   r  r  r   r  r   r   r  )rz   r   r  r  r  r!  r  ri   
line_widthr   r#  r?   r?   r@   r  "  s     


r  )r   r,   r8   c                 C   s   i }|D ]}|j d usJ t|j ts4J ||j ft|j dksPJ ||j f|j \}}}t| t|}t|di }|jdkrd|v rd|vr|d |f}n
|||f}||g 	| qg }	|
 D ]\}}
|		t|
g|R  q|	S )NrE  keywordsr   skipZ
pytestmark)r  r   r  r   r$   r   rG   r   r   rX  r   )r   r,   deventr   r  r"  r  r  rC   eventsr?   r?   r@   r  >  s*    
r  r  r  r  )r*   r1   r0   r+   )rV   nounr8   c                 C   s4   |dvr| |fS | dd}| | dkr.|d n|fS )N)r1   r0   r  r0   warningrE   r   )r   )rV   r  r?   r?   r@   r  f  s    r  r   c                 C   sJ   g }| D ]<\}}dj |d}|dr2|dd  }||vr|| q|S )Nz"{dist.project_name}-{dist.version})distzpytest-   )r1  r  rX  )rZ  rC   r  r  rk  r?   r?   r@   rY  s  s    
rY  )secondsr8   c                 C   s:   | dk r| ddS t jt| d}| dd| dS dS )zQFormat the given seconds in a human readable manner to show in the final summary.<   z.2fr   )r  zs (r  N)datetime	timedeltaru   )r  dtr?   r?   r@   r    s    r  c                 C   s   t | dr4tt| j}|dr0|tdd }|S | js>J t| jt	sNJ | j\}}}|drv|tdd }n|dkrd}|S dS )zqGet the reason string of a skip/xfail/xpass test report.

    The string is just the part given by the user.
    r  zreason: Nr  ZSkippedr   )
r  r   rN   r  r  r   r,   r   r  r  )r   r"  r.  r?   r?   r@   r    s    



r  )^rM   rQ   dataclassesr  rg  rI  r   r0   collectionsr   	functoolsr   pathlibr   typingr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   rM  Z_pytest._versionr   r   r   Z_pytest._coder   Z_pytest._code.coder   Z_pytest._ior   Z_pytest._io.wcwidthr   Z_pytest.assertion.utilr   Z_pytest.compatr   r   r   r   r   r   Z_pytest.config.argparsingr    Z_pytest.nodesr!   r"   Z_pytest.pathlibr#   r$   Z_pytest.reportsr%   r&   r'   Ztyping_extensionsr(   Z_pytest.mainr)   r?  r  rv   Actionr2   rx   r   rN   r   r   	dataclassr   r   r  ru   r  rP   r  r  r  r  r  rY  floatr  r  r?   r?   r?   r@   <module>   s   %|       E
 	