a
    !f                     @   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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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/m0Z0 ddl1m2Z2 ddl1m3Z3 dd l1m4Z4 dd!l1m5Z5 dd"l6m7Z7 dd#l8m9Z9 dd$l8m:Z: dd%l;m<Z< dd&l;m=Z= dd'l>m?Z? dd(l>m@Z@ dd)l>mAZA erFdd*lBmCZC dd+lDmEZE d,ZFd-ZGd.ZHG d/d0 d0ejIZJG d1d2 d2eZKe7dd3d4d5ZLe3dd6d7d8ZMe3eNd6d9d:ZOe5d;d<e?eeNeNeNf d=d>d?ZPejQG d@dA dAZRe0G dBdC dCZSe*e3e?dDdEdFZTeNeNeUeeN dGdHdIZVe3e?e*eeNeWf eNdJdKdLZXeee@ eeeUeNeeU eNf  dMdNdOZYdPdPdQdRdSZZdQZ[eUeNeeUeNf dTdUdVZ\eeN dWdXdYZ]e^eNdZd[d\Z_eAeNd=d]d^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)
NamedTuple)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   )r4   r5   nargsr6   r7   r8   )super__init__)selfr4   r5   r6   r7   r8   	__class__ Q/var/www/html/python-backend/venv/lib/python3.9/site-packages/_pytest/terminal.pyr<   V   s    zMoreQuietAction.__init__)parser	namespacevaluesoption_stringr9   c                 C   s6   t || jdd }t|| j| t |ddd |_d S )Nr      quiet)getattrr5   setattrrG   )r=   rB   rC   rD   rE   Z	new_countr@   r@   rA   __call__g   s    zMoreQuietAction.__call__)NFN)N)__name__
__module____qualname____doc__r   strobjectboolr   r<   argparseArgumentParser	Namespacer   rJ   __classcell__r@   r@   r>   rA   r3   O   s(   
    r3   c                   @   sB   e Zd ZU dZeed< eed< eeeeeee	f f f ed< dS )TestShortLogReportuG  Used to store the test status result category, shortletter and verbose word.
    For example ``"rerun", "R", ("RERUN", {"yellow": True})``.

    :ivar category:
        The class of result, for example ``“passed”``, ``“skipped”``, ``“error”``, or the empty string.

    :ivar letter:
        The short letter shown as testing progresses, for example ``"."``, ``"s"``, ``"E"``, or the empty string.

    :ivar word:
        Verbose word is shown as testing progresses in verbose mode, for example ``"PASSED"``, ``"SKIPPED"``,
        ``"ERROR"``, or the empty string.
    categoryletterwordN)
rK   rL   rM   rN   rO   __annotations__r   r   r   rQ   r@   r@   r@   rA   rV   t   s   
rV   )rB   r9   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)actionr6   r5   r8   z--no-header
store_trueF	no_headerzDisable headerz--no-summary
no_summaryzDisable summaryz-qz--quietzDecrease verbosityz--verbosityzSet verbosity. Default: 0.)r5   typer6   r8   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').)r^   r5   r6   metavarr8   z--disable-warningsz--disable-pytest-warningsdisable_warningszDisable warnings summary)r6   r5   r^   r8   z-lz--showlocalsZ
showlocalsz/Show locals in tracebacks (disabled by default))r^   r5   r6   r8   z--no-showlocalsstore_falsezFHide locals in tracebacks (negate --showlocals passed through addopts))r^   r5   r8   z--tbstyletbstyleauto)rk   longshortnolinenativez5Traceback print mode (auto/long/short/line/native/no))rf   r^   r5   r6   choicesr8   z--show-captureshowcapture)rn   stdoutstderrlogallrv   zOControls how captured stdout/stderr/log is shown on failed tests. Default: all.)r^   r5   rq   r6   r8   z--fulltracez--full-tracez,Don't cut any tracebacks (default is to cut))r^   r6   r8   z--colorcolor)yesrn   rk   z#Color terminal output (yes/no/auto)z--code-highlightrx   rn   zSWhether code should be highlighted (only if --color is also enabled). Default: yes.)r6   rq   r8   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)r8   r6   )ZgetgroupZ
_addoptionr3   int_REPORTCHARS_DEFAULTZaddini)rB   groupr@   r@   rA   pytest_addoption   s    			r~   configr9   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maprO   
write_line)tagsargsmsgreporterr@   rA   mywriter	  s    z"pytest_configure.<locals>.mywriterzpytest:config)TerminalReportersysrs   pluginmanagerregisteroptiondebugtraceconfigtracerootZsetprocessor)r   r   r@   r   rA   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   rd   lowerrg   replace)r   rd   Zold_aliasesZ
reportoptscharr@   r@   rA   getreportopt  s&    

r   TZtrylastreportr9   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+   r2   E)r,   r-   outcomewhenupper)r   rX   r   r@   r@   rA   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_summaryr   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=   r   filenameZlinenumrelpathr@   r@   rA   get_locationK  s    
zWarningReport.get_location)rK   rL   rM   rN   rO   rZ   r   r   r   r   r{   r   r   r   r   r@   r@   r@   rA   r   9  s   

r   c                   @   sB  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$d%d&eee	ee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d0d1d2Zeedd0d3d4Zdeee ee	 edd5d6d7Zdeeedd9d:d;Zeedd<d=d>Z ee!e" dd?d@dAZ#e$edBdCdDZ%e&j'eddEdFdGZ(e)ddHdIdJZ*e!e+ ddKdLdMZ,ee-eee	 ef ddNdOdPZ.e/ddQdRdSZ0eeddTdUZ1eddVdWdXZ2eddYdZZ3ddd[d\Z4ee	dd]d^Z5ddd_d`Z6e7ddQdadbZ8deddcdddeZ9e:dfdgdhddidjdkZ;e!eee!e f  ddldmdnZ<ee=e dodpdqZ>dhddidrdsZ?e!e+ ddKdtduZ@e:dfdvdhee	eAf dwdxdyZBe:dfdveCdz dd{d|ZDeEeF dd}d~dZGddddZHddddZIeeee	 eedddZJdd ZKdd ZLedddZMddddZNddddZOee=e/ dVddZPeddVddZQe/ddddZRddddZSddddZTeUddddZVddddZWddddZXe-ee=e f dddZYeedddZZddddZ[e-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)r   filer9   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.configr   _numcollected_session_showfspathstats_main_color_known_typesr   r   	startpathr   rs   Zcreate_terminal_writer_tw	fullwidth_screen_widthcurrentfspathr   rd   Z	hasmarkupisattyset_progress_nodeids_reported_determine_show_progress_info_show_progress_info_collect_report_last_write_already_displayed_warnings_keyboardinterrupt_memo)r=   r   r   _pytestr@   r@   rA   r<   X  s,    





zTerminalReporter.__init__z#Literal['progress', 'count', False]r9   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.capturern   ry   zprogress-even-when-capture-noFZ	setupshowrz   r\   N)r   	getoptiongetini)r=   cfgr@   r@   rA   r   r  s    
z.TerminalReporter._determine_show_progress_infoc                 C   s   | j jj}|S N)r   r   r]   )r=   	verbosityr@   r@   rA   r     s    
zTerminalReporter.verbosityc                 C   s
   | j dkS r   r   r=   r@   r@   rA   
showheader  s    zTerminalReporter.showheaderc                 C   s   t | jjjS r   )rQ   r   r   r`   r   r@   r@   rA   r`     s    zTerminalReporter.no_headerc                 C   s   t | jjjS r   )rQ   r   r   ra   r   r@   r@   rA   ra     s    zTerminalReporter.no_summaryc                 C   s   | j d u r| jdkS | j S r   )r   r   r   r@   r@   rA   
showfspath  s    

zTerminalReporter.showfspath)valuer9   c                 C   s
   || _ d S r   )r   )r=   r   r@   r@   rA   r     s    c                 C   s
   | j dkS r   r   r   r@   r@   rA   showlongtestinfo  s    z!TerminalReporter.showlongtestinfo)r   r9   c                 C   s   ddd ||}|| jv S )Nxr   )r/   r-   )getrd   )r=   r   r@   r@   rA   hasopt  s    zTerminalReporter.hasopt)r   markupr9   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)r   rootpathsplitr   r   )_write_progress_information_filling_spacer%   r   r   ro   write)r=   r   resr   fspathZ	relfspathr@   r@   rA   write_fspath_result  s    
z$TerminalReporter.write_fspath_resultr   )prefixextrar9   c                 K   sH   | j |kr&| j  || _ | j| |rD| jj|fi | d| _ d S )N)r   r   ro   r   )r=   r   r   kwargsr@   r@   rA   write_ensure_prefix  s    

z$TerminalReporter.write_ensure_prefixc                 C   s   | j r| j  d | _ d S r   )r   r   ro   r   r@   r@   rA   ensure_newline  s    
zTerminalReporter.ensure_newlineF   
)r   marginline_sep)contentr   r   r   r   r9   c                K   sV   | j j}|tjd| | | j| ddd}||d }| j j|fd|i| dS )z+Wrap message with margin for progress info.r   TF)widthdrop_whitespacereplace_whitespaceNr   )r   width_of_current_liner   textwrapwrapr   r   )r=   r   r   r   r   r   r   wrappedr@   r@   rA   
wrap_write  s    

zTerminalReporter.wrap_write)r   )r   r   r   r9   c                K   s   | j j|fd|i| d S )Nr   )r   r   )r=   r   r   r   r@   r@   rA   r     s    zTerminalReporter.writec                 C   s   | j   d S r   )r   r   r   r@   r@   rA   r     s    zTerminalReporter.flush)ro   r   r9   c                 K   s6   t |tst|dd}|   | jj|fi | d S )Nr   )errors)
isinstancerO   r   r   ro   )r=   ro   r   r@   r@   rA   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.
        eraseFrF   r   r   N)popr   r   lenrO   r   )r=   ro   r   r   Z
fill_countfillr@   r@   rA   rewrite  s    	
zTerminalReporter.rewrite)septitler   r   r9   c                 K   s$   |    | jj|||fi | d S r   )r   r   r  )r=   r  r  r   r   r@   r@   rA   	write_sep  s    zTerminalReporter.write_sep=)r  r  kwr9   c                 K   s   | j j||fi | d S r   )r   r  )r=   r  r  r	  r@   r@   rA   section  s    zTerminalReporter.section)r   r	  r9   c                 K   s   | j j|fi | d S r   )r   ro   )r=   r   r	  r@   r@   rA   ro     s    zTerminalReporter.line)rW   itemsr9   c                 C   s.   || j v}| j |g | |r*|   d S r   )r   
setdefaultextend_set_main_color)r=   rW   r  Zset_main_colorr@   r@   rA   
_add_stats  s    
zTerminalReporter._add_stats)excreprr9   c                 C   s&   t |dD ]}| d|  qdS )Nr   zINTERNALERROR> T)rO   r   r   )r=   r  ro   r@   r@   rA   pytest_internalerror  s    z%TerminalReporter.pytest_internalerror)warning_messager   r9   c                 C   s@   ddl m} |j|jf}||}t|||d}| d|g d S )Nr   )warning_record_to_str)r   r   r   r1   )Z_pytest.warningsr  r   linenor   r  )r=   r  r   r  r   r   Zwarning_reportr@   r@   rA   pytest_warning_recorded  s    z(TerminalReporter.pytest_warning_recorded)pluginr9   c                 C   s"   | j jjrd| }| | d S )NzPLUGIN registered: )r   r   r   r   )r=   r  r   r@   r@   rA   pytest_plugin_registered!  s    

z)TerminalReporter.pytest_plugin_registered)r  r9   c                 C   s   |  d| d S )Nr.   )r  )r=   r  r@   r@   rA   pytest_deselected)  s    z"TerminalReporter.pytest_deselected)r   locationr9   c                 C   sL   | j r.| j|g|R  }| |d |   n| jrH| |d |   d S )Nr   )r   _locationliner   r   r   r   )r=   r   r  ro   r@   r@   rA   pytest_runtest_logstart,  s    
z(TerminalReporter.pytest_runtest_logstartr   c                 C   sB  d| _ |}t| jjj|| jd }|j|j|j  }}}t|t	sHd }n|\}}| 
||g |sj|sjd 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 | nB| j|j | j|jg|jR  }
|s| j|
|fi | |jsFt|drt|}| jjjd	k r| jj| jj td
 d }td||}nd| d}|r|d ur| | | j r6| !  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   r   nodewasxfailgreenyellowredr       [100%]rF   z ({})z ()z[%s]r   )cyanr   ))Z
_tests_ranrV   r   hookr   rW   rX   rY   r   tupler  hasattrr,   r+   r-   r   r   r   r   addr   r  r  r   _get_raw_skip_reasonr   r]   r   r   r  _format_trimmedr   r   r   r   r  Zgatewayid!_get_progress_information_messager   r   )r=   r   repr   rW   rX   rY   r   Zrunning_xdistZ	was_xfailro   reasonavailable_widthZformatted_reasonr@   r@   rA   pytest_runtest_logreport9  st    











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@   rA   _is_last_item}  s    zTerminalReporter._is_last_itemr   r9   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   r\    [/]r"  rF   r   T)r   r   r   r1  r  r   r(  r2  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@   rA   pytest_runtest_logfinish  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 )Nr\   z{:zd}r4  z/{}]z [ z / z ]z	 [{:3d}%]d   r"  )r   r1  r   r   r  rO   format)r=   	collectedrz   Zcounter_formatformat_stringr@   r@   rA   r,    s    

z2TerminalReporter._get_progress_information_messagec                 C   sN   |   \}}|  }| j}| jj| d }| j||fddi|di d S )NrF   r   T)r7  r,  r8  r   r   r   rjust)r=   rw   r:  r   r   r  r@   r@   rA   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@   rA   r8    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   boldrF   )r   r   r   r]   r   r   timer   r   r@   r@   rA   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 )Nr2   r-   c                 S   s   g | ]}t |tr|qS r@   )r   r"   .0r   r@   r@   rA   
<listcomp>      z9TerminalReporter.pytest_collectreport.<locals>.<listcomp>)r+   r  r-   resultr   r  r   report_collect)r=   r   r  r@   r@   rA   pytest_collectreport  s    z%TerminalReporter.pytest_collectreport)r   r9   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   r2   r-   r.   z
collected zcollecting z itemrF   r   r   z / %d error%sz / %d deselectedz / %d skippedz / %d selectedT)rA  r   r   )r   r   r]   r   rB  r   REPORT_COLLECTING_RESOLUTIONr  r   r   r   rO   r   r  r   r   )r=   r   tr   r-   r.   selectedro   r@   r@   rA   rI    s>    
zTerminalReporter.report_collectTr   r*   )sessionr9   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rA  z	platform z -- Python pypy_version_infor      z[pypy--r6  z, pytest-{}, pluggy-{}r   Zpastebinz -- )r   
start_path)r   r   rB  _sessionstarttimer   r  platformpython_versionr`   r   rH   r   r   rO   r=  r   _versionversionpluggy__version__r   r   r   r   
executabler   r%  pytest_report_headerr   _write_report_lines_from_hooks)r=   rN  Zverinfor   rP  linesr@   r@   rA   pytest_sessionstart  s6    


z$TerminalReporter.pytest_sessionstartr^  r9   c                 C   s<   t |D ].}t|tr"| | q|D ]}| | q&qd S r   )reversedr   rO   r   )r=   r^  Zline_or_linesro   r@   r@   rA   r]    s
    
z/TerminalReporter._write_report_lines_from_hooksr   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   r=  r   r   Zlist_plugin_distinfo_plugin_nameversions)r=   r   rH  rb  
plugininfor@   r@   rA   r\    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)r   rS  r  collectonlyr   r+   !zcollection failures)rI  r   r%  Zpytest_report_collectionfinishr   r  r]  r   r   r]   r   ro   _printcollecteditemsr   r   r  
toterminal)r=   rN  r^  r+   r-  r@   r@   rA   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   rh  c                 s   s    | ]}|j d dd V  qdS r   rF   r   N)r   r   )rE  itemr@   r@   rA   	<genexpr>:  rG  z8TerminalReporter._printcollecteditems.<locals>.<genexpr>z%s: %dr   rF     objz{}{})r   r   r]   r   sortedr  r   ro   r   Z	listchainr  r  rd  rH   inspectgetdoc
splitlinesr=  )r=   r  countsnamer\   rn  stackindentZneeded_collectorscolrq  docro   r@   r@   rA   rj  7  s4    

z%TerminalReporter._printcollecteditems)Zhookwrapper)rN  
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   r|  r   ri  T)r   )Z
get_resultr   ro   r   OKZTESTS_FAILEDZINTERRUPTEDZUSAGE_ERRORZNO_TESTS_COLLECTEDra   r   r%  pytest_terminal_summaryZ
shouldfailr  rO   _report_keyboardinterruptr   Z
shouldstopsummary_stats)r=   rN  r|  r   Zsummary_exit_codesr@   r@   rA   pytest_sessionfinishT  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@   rA   r~  o  s    z(TerminalReporter.pytest_terminal_summary)excinfor9   c                 C   s   |j dd| _d S )NT)Zfuncargs)Zgetreprr   )r=   r  r@   r@   rA   pytest_keyboard_interruptz  s    z*TerminalReporter.pytest_keyboard_interruptc                 C   s   | j d ur|   d S r   )r   r  r   r@   r@   rA   pytest_unconfigure}  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 )Nri  KeyboardInterruptz@(to show a full traceback on KeyboardInterrupt use --full-trace)T)r  )
r   	reprcrashr   r  r   r   Z	fulltracerk  r   ro   )r=   r  r   r@   r@   rA   r    s    
z*TerminalReporter._report_keyboardinterrupt)r   r   r  domainr9   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 )Nr3  c                    s\   j | } rX| rX|d t   } d}|d dd|d< |d|7 }|S )N[r   r   r   )r   cwd_relative_nodeidendswithr  r   r   r   )r   ro   rD   r  r=   r@   rA   mkrel  s    
z-TerminalReporter._locationline.<locals>.mkrelr!  r   r   \z <- z
[location]r   )	rO   r   r   r   r   ZSEPr%   r   r   )r=   r   r   r  r  r  r   r@   r  rA   r    s    
zTerminalReporter._locationlinec                 C   s   |j }|r|S dS )Nztest session)	head_line)r=   r-  r  r@   r@   rA   _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   )rO   longreprr  AttributeError)r=   r-  r@   r@   rA   _getcrashline  s    zTerminalReporter._getcrashline)rw  c                 C   s   dd | j |dD S )Nc                 S   s   g | ]}t |d s|qS )Z	_pdbshown)r'  rD  r@   r@   rA   rF    rG  z/TerminalReporter.getreports.<locals>.<listcomp>r@   r   r   )r=   rw  r@   r@   rA   
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   r1   )reportsr9   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 rm  )rO   r   )rE  locr@   r@   rA   ro    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{}rF   r   r   N)r=  )rE  kvr@   r@   rA   ro    s   )	r   r   rd  r  r   r   rO   r   r  )r  	locationsr   r  Zcounts_by_filenamer   r@   rA   collapsed_location_report  s    
zDTerminalReporter.summary_warnings.<locals>.collapsed_location_reportzwarnings summary (final)zwarnings summaryr  TF)r  rA  r   c                 s   s   | ]}d | V  qdS )rp  Nr@   rD  r@   r@   rA   ro    rG  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   rd  r   r   rO   r  r  r   ro   ru  r   rstrip)r=   Zall_warningsr   Zwarning_reportsZreports_grouped_by_messagewrr  r  r   Zmessage_reportsZmaybe_locationr^  Zindentedr@   r   rA   r    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 )	Nrn   Pr,   r  ZPASSESr:  T)r  rA  )r   r   rj   r   r  r  sectionsr  _outrep_summary_handle_teardown_sectionsr   r=   r  r-  r   r@   r@   rA   r    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   )rE  r   r   r@   rA   rF    s   z:TerminalReporter._get_teardown_reports.<locals>.<listcomp>)r  )r=   r   r  r@   r  rA   _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@   rA   r  	  s    z*TerminalReporter._handle_teardown_sections)r-  r9   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 )Nrn   rv   r   rR  rh  r   )r   r   rr   r  r   r  ro   r=   r-  rr   Zsecnamer   r@   r@   rA   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 )	Nrn   r+   r  ZFAILURESro   r:  Tr   rA  )r   r   rj   r  r  r  r   r  r  r  r   )r=   r  r-  ro   r   r@   r@   rA   r    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 )Nrn   r2   r  ZERRORSr   zERROR collecting z	ERROR at z of r:  Tr  )	r   r   rj   r  r  r   r  r   r  r  r@   r@   rA   r  +  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 )Nrn   rv   rR  rh  r   )rk  r   r   r   rr   r  r  ro   r  r@   r@   rA   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 )Nrh  r   rc  Tz in r   z[0mr  r   )r   )r   r   rB  rT  build_summary_stats_liner   r   r   r  rd  r   format_session_durationr  r  r   )r=   Zsession_durationpartsr9  Z
line_partsZdisplay_sepr   textr   Zwith_markupr   Zmain_markupdurationZduration_with_markupZmarkup_for_end_sepr@   r@   rA   r  G  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)r^  statr9   c                   sT    j |g }|sd S  j}|D ].}t|t}t|| j|di}| | q d S )NT)r   r   r   _color_for_type_color_for_type_default _get_line_with_reprcrash_messager   rd  )r^  r  r+   r   r-  rw   ro   r   r@   rA   show_simplep  s    z8TerminalReporter.short_test_summary.<locals>.show_simpler`  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/   r1   Tr    - )r   r   _get_verbose_wordr   r   r   r  _get_node_id_with_markupr  rO   rd  )r^  r/   r-  verbose_wordmarkup_wordr   ro   r.  r   r@   rA   show_xfailed|  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 )Nr0   r1   Tr   )
r   r   r  r   r   r   r  r  r  rd  )r^  r0   r-  r  r  r   r.  r   r@   rA   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   r1   T	Skipped: z%s [%d] %s:%d: %sz%s [%d] %s: %s)r   r   _folded_skipsr   r  r   r   r   r  
startswithr  rd  )
r^  r-   Zfskipsr  r  r   numr   r  r.  r   r@   rA   show_skipped  s&    

z9TerminalReporter.short_test_summary.<locals>.show_skippedr+   )r  r,   r2   )r   Xfr   pr   r  zshort test summary infoT)r$  rA  )rd   r   rO   r   r   r  r   )
r=   r  r  r  r  ZREPORTCHAR_ACTIONSr^  r   r^   ro   r@   r   rA   r  l  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   r2  r  r   r@   r@   rA   r7    s
    

z TerminalReporter._get_main_color)unknown_type_seenr9   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+   r2   r   r1   r0   r  r,   r  )r   r2  )r=   r  r   r9  r@   r@   rA   _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_TYPESrd  listr   r  rQ   r   )r=   Zunknown_typesZ
found_typer@   r@   rA   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.
        rg  N)r   r   &_build_collect_only_summary_stats_line _build_normal_summary_stats_liner   r@   r@   rA   r    s    z)TerminalReporter.build_summary_stats_line)keyr9   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)rH   rD  r@   r@   rA   rF    rG  z<TerminalReporter._get_reports_to_display.<locals>.<listcomp>r  )r=   r  r  r@   r@   rA   _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 )NTrA  %d %szno tests ran)r7  r  r  r  r   r  rd  	pluralize)	r=   r9  Zknown_typesr  r  r  r\   rw   r   r@   r@   rA   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.   r2   r   zno tests collectedr  Tr  z%d %s collectedtestzno tests collected (z deselected)r5  z tests collected (r  )r  r  r   r  r  )r=   r.   r   r  r9  Zcollected_outputZall_tests_were_deselectedrM  r@   r@   rA   r    s*    


z7TerminalReporter._build_collect_only_summary_stats_line)N)r   )NN)r  )F)arK   rL   rM   r   r   r   r<   r   propertyr{   r   rQ   r   r`   ra   r   setterr   rO   r   r   r   r   r   r   r   r   bytesr   r  r  r
  ro   r   r   r  r   r  r1   WarningMessager  r   r  r"   r  r   r  r(   r0  r2  r;  r,  r   r8  rC  r'   rJ  rI  r    r_  r]  r   r\  rl  rj  r   r  r
   r~  r   BaseExceptionr  r  r  r  r  r  r  r  r  r  r  r  r  r  r&   r  r  r  r7  r  r  r	   r  r  r  r  r@   r@   r@   rA   r   V  s   		  
D
%

6%R	*r   )twr   r-  c                 C   sF   | |j}|d^}}|r>| jd|dd}|d | S |S d S )Nr   TrO  )r  r   r   r   r   )r  r   r-  r   pathr  Zparts_markupr@   r@   rA   r  ,  s    r  )r=  r   r/  r9   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   rh  Nz...r   )findr   r=  r  )r=  r   r/  iellipsisZformat_widthr@   r@   rA   r*  6  s    
r*  )r   r-  r  word_markupr9   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*  )r   r-  r  r  r  rY   r  ro   
line_widthr   r/  r@   r@   rA   r  O  s     


r  )r   r-   r9   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 )NrQ  keywordsr   skipZ
pytestmark)r  r   r&  r  r%   r   rH   r   r  rd  r  )r   r-   deventr   r  r.  r  r  rD   eventsr@   r@   rA   r  k  s*    
r  r   r  r  )r+   r2   r1   r,   )r\   nounr9   c                 C   s4   |dvr| |fS | dd}| | dkr.|d n|fS )N)r2   r1   r  r1   warningrF   r   )r   )r\   r  r@   r@   rA   r    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-   )r=  r  rd  )rf  rD   r  r  rw  r@   r@   rA   re    s    
re  )secondsr9   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	timedeltar{   )r  dtr@   r@   rA   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   rO   r  r  r  r-   r   r  r&  )r   r.  r:  r@   r@   rA   r)    s    



r)  )arN   rR   dataclassesr  rs  rU  r   r   r1   collectionsr   	functoolsr   pathlibr   typingr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   rY  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*   rK  r  r|   Actionr3   rV   r~   r   rO   r   r   	dataclassr   r   r  r{   r*  rQ   r  r  r  r  r  re  floatr  r)  r@   r@   r@   rA   <module>   s   %|       \
 	