B
    Wc                 @   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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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jNd8d=G d>d? d?ZOe.G d@dA dAZPe(e1e=dBdCdDZQeKeKeReeK dEdFdGZSe1e=e(eeKeTf eKdHdIdJZUeee> eeeReKeeR eKf  dKdLdMZVdNdNdOdPdQZWdOZXeReKeeReKf dRdSdTZYeeK dUdVdWZZe[eKdXdYdZZ\e?eKd: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)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__ /lib/python3.7/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   setattrrE   )r<   r@   rA   rB   rC   Z	new_countr>   r>   r?   __call__e   s    zMoreQuietAction.__call__)NFN)N)__name__
__module____qualname____doc__r   strobjectboolr   r;   argparseArgumentParserZ	Namespacer   rH   __classcell__r>   r>   )r=   r?   r2   M   s      r2   )r@   r8   c             C   sl  | 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d0d1d1d2d3d4d5d6gd7d8 |jd9dd:d4d;d<d=d>gd>d?d@ |jdAdBdddCdD |jdEdFddFd1dGd4d1gdHd8 |jdIdGdGd4gdJdK | jdLdMdNdO d S )PNzterminal reportingZ	ReportingZgeneral)Z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-rZ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').)rU   r4   r5   metavarr7   z--disable-warningsz--disable-pytest-warningsdisable_warningszDisable warnings summary)r5   r4   rU   r7   z-lz--showlocalsZ
showlocalsz/Show locals in tracebacks (disabled by default))rU   r4   r5   r7   z--no-showlocalsZstore_falsezFHide locals in tracebacks (negate --showlocals passed through addopts))rU   r4   r7   z--tbZstyletbstyleautoZlongZshortnolineZnativez5Traceback print mode (auto/long/short/line/native/no))r\   rU   r4   r5   choicesr7   z--show-captureshowcapturestdoutstderrlogallzOControls how captured stdout/stderr/log is shown on failed tests. Default: all.)rU   r4   rb   r5   r7   z--fulltracez--full-tracez,Don't cut any tracebacks (default is to cut))rU   r5   r7   z--colorcolorZyesz#Color terminal output (yes/no/auto)z--code-highlightzSWhether code should be highlighted (only if --color is also enabled). Default: yes.)r5   rb   r7   console_output_stylezfConsole output: "classic", or with additional progress information ("progress" (percentage) | "count")progress)r7   r5   )ZgetgroupZ
_addoptionr2   int_REPORTCHARS_DEFAULTZaddini)r@   groupr>   r>   r?   pytest_addoptionr   s    rn   )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maprM   
write_line)Ztagsargsmsg)reporterr>   r?   mywriter   s    z"pytest_configure.<locals>.mywriterzpytest:config)TerminalReportersysrd   pluginmanagerregisteroptiondebugtraceconfigZtracerootZsetprocessor)ro   rx   r>   )rw   r?   pytest_configure   s
    r   c             C   s   | j j}ddh}d}xV|D ]N}||kr.| }|dkr<d}q|dkrJd}q|dkrXd}q||kr||7 }qW | j jsd	|krd	| }n| j jrd	|kr|d	d}|S )
NFS aZsxXEfAZPpsxXEfNw)r}   rZ   lowerr]   replace)ro   rZ   Zold_aliasesZ
reportoptscharr>   r>   r?   getreportopt   s&    

r   T)trylast)reportr8   c             C   sH   d}| j rd}n
| jrd}| j}| jdk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   )Zauto_attribsc               @   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_summary)ro   r8   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<   ro   filenameZlinenumrelpathr>   r>   r?   get_location4  s    
zWarningReport.get_location)rI   rJ   rK   rL   rM   __annotations__r   r   r   r   rk   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 )ry   N)ro   filer8   c             C   s   dd l }|| _d| _d | _d | _i | _d | _d | _|jj	| _
|d krJtj}|j||| _| jj| _d | _t|| _| jj| _| | _t | _|  | _d | _d | _d | _d S )Nr   )_pytest.configro   _numcollected_session_showfspathstats_main_color_known_typesr   r   	startpathrz   rd   Zcreate_terminal_writer_tw	fullwidth_screen_widthcurrentfspathr   rZ   Z	hasmarkupisattyset_progress_nodeids_reported_determine_show_progress_info_show_progress_info_collect_report_last_write_already_displayed_warnings_keyboardinterrupt_memo)r<   ro   r   _pytestr>   r>   r?   r;   A  s,    





zTerminalReporter.__init__z#Literal['progress', 'count', False])r8   c             C   sT   | j dddkrdS | j ddr(dS | j d}|dkr@dS |dkrLdS dS dS )	zRReturn whether we should display progress information based on the current config.Zcapturer`   FZ	setupshowri   rj   rS   N)ro   	getoptiongetini)r<   Zcfgr>   r>   r?   r   [  s    z.TerminalReporter._determine_show_progress_infoc             C   s   | j jj}|S )N)ro   r}   rT   )r<   	verbosityr>   r>   r?   r   k  s    
zTerminalReporter.verbosityc             C   s
   | j dkS )Nr   )r   )r<   r>   r>   r?   
showheaderp  s    zTerminalReporter.showheaderc             C   s   t | jjjS )N)rO   ro   r}   rW   )r<   r>   r>   r?   rW   t  s    zTerminalReporter.no_headerc             C   s   t | jjjS )N)rO   ro   r}   rX   )r<   r>   r>   r?   rX   x  s    zTerminalReporter.no_summaryc             C   s   | j d kr| jdkS | j S )Nr   )r   r   )r<   r>   r>   r?   
showfspath|  s    

zTerminalReporter.showfspath)valuer8   c             C   s
   || _ d S )N)r   )r<   r   r>   r>   r?   r     s    c             C   s
   | j dkS )Nr   )r   )r<   r>   r>   r?   showlongtestinfo  s    z!TerminalReporter.showlongtestinfo)r   r8   c             C   s   ddd ||}|| jkS )Nxr   )r.   r,   )getrZ   )r<   r   r>   r>   r?   hasopt  s    zTerminalReporter.hasopt)r   markupr8   c             K   s   | j j|dd  }| jd ks*|| jkrn| jd k	rB| jrB|   || _t| j|}| j	  | j
|d  | jj
|fddi| d S )Nz::r   rq   flushT)ro   rootpathsplitr   r   )_write_progress_information_filling_spacer$   r   r   ra   write)r<   r   resr   fspathZ	relfspathr>   r>   r?   write_fspath_result  s    
z$TerminalReporter.write_fspath_resultr   )prefixextrar8   c             K   sD   | j |kr&| j  || _ | j| |r@| jj|f| d| _ d S )N)r   r   ra   r   )r<   r   r   kwargsr>   r>   r?   write_ensure_prefix  s    

z$TerminalReporter.write_ensure_prefixc             C   s   | j r| j  d | _ d S )N)r   r   ra   )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 )N)r   r   )r<   r>   r>   r?   r     s    zTerminalReporter.flush)ra   r   r8   c             K   s2   t |tst|dd}|   | jj|f| d S )Nr   )errors)
isinstancerM   r   r   ra   )r<   ra   r   r>   r>   r?   rt     s    
zTerminalReporter.write_linec             K   sV   | dd}|r.| jjt| d }d| }nd}t|}| jjd| | f| 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.
        eraseFrD   rq   r   N)popr   r   lenrM   r   )r<   ra   r   r   Z
fill_countfillr>   r>   r?   rewrite  s    	
zTerminalReporter.rewrite)septitler   r   r8   c             K   s    |    | jj|||f| d S )N)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| d S )N)r   r   )r<   r   r   r   r>   r>   r?   section  s    zTerminalReporter.section)rv   r   r8   c             K   s   | j j|f| d S )N)r   ra   )r<   rv   r   r>   r>   r?   ra     s    zTerminalReporter.line)categoryitemsr8   c             C   s.   || j k}| j |g | |r*|   d S )N)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*   x$t |dD ]}| d|  qW dS )N
zINTERNALERROR> T)rM   r   rt   )r<   r   ra   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: )ro   r}   r   rt   )r<   r   rv   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   sJ   | j r,| j|f| }| |d |   n| jrF| |d |   d S )Nr   )r   _locationliner   r   r   r   )r<   r   r   ra   r>   r>   r?   pytest_runtest_logstart  s    
z(TerminalReporter.pytest_runtest_logstart)r   r8   c             C   s&  d| _ |}| jjj|| jd}|\}}}t|ts8d }n|\}}| ||g |sZ|sZd S t|d}|d k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| n:| j|j | j|jf|j }
|s| j|
|f| |j
s,t|drt|}| jjjd	k rn| jj| jj td
 d }td||}nd| d}|r|d k	r| j| | jr|   nr|   | jd|jjj   | jr| jj| ! d dd n| jd | jj|f| | jd|
  d| _"| #  d S )NT)r   ro   nodewasxfailgreenyellowredr      z [100%]rD   z ({})z ()z[%s]rq   )cyanr   )$Z
_tests_ranro   hookr   r   tupler   hasattrr+   r*   r,   r   r   r   r   addr   r   r   r   _get_raw_skip_reasonr}   rT   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_xfailra   reasonavailable_widthZformatted_reasonr>   r>   r?   pytest_runtest_logreport  sb    











z)TerminalReporter.pytest_runtest_logreportc             C   s    | j d k	stt| j| j jkS )N)r   AssertionErrorr   r   testscollected)r<   r>   r>   r?   _is_last_itemJ  s    zTerminalReporter._is_last_item)r   r8   c       	      C   s   | j s
t| jdkr| jr| jdkrD| j j}td| d| d}ntd}| j| | jrh| 	  nH| 
 \}}| j}|| d | jk}|r|  }| jj|d f|d	i d S )
Nr   rS   z [/]z [100%]rD   r   T)r   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_edgerv   r>   r>   r?   pytest_runtest_logfinishO  s    


z)TerminalReporter.pytest_runtest_logfinishc             C   s   | j s
t| 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 )NrS   z{:zd}z [z/{}]z [ z / z ]z	 [{:3d}%]d   z [100%])r   r  r  r   r   r   rM   format)r<   Z	collectedrj   Zcounter_formatformat_stringr>   r>   r?   r  d  s    

z2TerminalReporter._get_progress_information_messagec             C   sN   |   \}}|  }| j}| jj| d }| j||fddi|di d S )NrD   r   T)r  r  r  r   r   r   rjust)r<   rh   r  rv   r   r   r>   r>   r?   r   u  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   boldrD   )r   ro   r}   rT   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>  s    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 k	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 itemrD   r   r   z / %d error%sz / %d deselectedz / %d skippedz / %d selectedT)r  r   r   )ro   r}   rT   r   r  r   REPORT_COLLECTING_RESOLUTIONr   r   r   r   rM   r   r   r   rt   )r<   r   tr   r,   r-   selectedra   r>   r>   r?   r!    s8    

"zTerminalReporter.report_collectT)r   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)r  z	platform z -- Python pypy_version_infor      z[pypy--r  z, pytest-{}, pluggy-{}r   Zpastebinz -- )ro   
start_path)r   r   r  _sessionstarttimer   r   platformZpython_versionrW   rz   rF   rr   rs   rM   r  r   Z_versionversionpluggy__version__r   ro   r}   r~   
executablert   r   pytest_report_headerr   _write_report_lines_from_hooks)r<   r&  Zverinforv   r'  linesr>   r>   r?   pytest_sessionstart  s,    



z$TerminalReporter.pytest_sessionstart)r3  r8   c             C   sD   x>t |D ]2}t|tr$| | q
x|D ]}| | q*W q
W d S )N)reversedr   rM   rt   )r<   r3  Zline_or_linesra   r>   r>   r?   r2    s
    

z/TerminalReporter._write_report_lines_from_hooks)ro   r8   c             C   s   d|j  }|jr&|dt|j |j 7 }|jtjjkrR|d}|dd	|7 }|g}|j
 }|r~|dd	t|  |S )Nzrootdir: %sz, configfile: 	testpathsz, testpaths: {}z, zplugins: %s)r   Zinipathr$   Zargs_sourcer   Z
ArgsSourceZ	TESTPATHSr   r  rr   r{   Zlist_plugin_distinfoappend_plugin_nameversions)r<   ro   ra   r6  r   
plugininfor>   r>   r?   r1    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 x|D ]}|| j
 qW d S )	NT)ro   r*  r   collectonlyr   r*   !zcollection failures)r!  ro   r   Zpytest_report_collectionfinishr   r   r2  r   r}   rT   r   ra   _printcollecteditemsr   r   r   
toterminal)r<   r&  r3  r*   r  r>   r>   r?   pytest_collection_finish  s     



z)TerminalReporter.pytest_collection_finishc          	   C   sv  | j jjdk r~| j jjdk r^tdd |D }xJt| D ]\}}| jd||f  q<W nx|D ]}| j|j qdW d S g }d}x|D ]}|	 dd  }x&|r||d t
| krP |  qW x|t
|d  D ]}	||	 t
|d d }| j| |	  | j jjdkrt|	d	d }
|
r6t|
nd }|rx*| D ]}| jd
|d | qHW qW qW d S )Nr   r;  c             s   s    | ]}|j d dd V  qdS )z::rD   r   N)r   r   )r  itemr>   r>   r?   	<genexpr>	  s    z8TerminalReporter._printcollecteditems.<locals>.<genexpr>z%s: %dr   rD   z  objz{}{})ro   r}   rT   r   sortedr   r   ra   r   Z	listchainr   r   r7  rF   inspectZgetdoc
splitlinesr  )r<   r   ZcountsnamerS   r@  stackindentZneeded_collectorscolrB  docra   r>   r>   r?   r=    s4    


z%TerminalReporter._printcollecteditems)Zhookwrapper)r&  
exitstatusc             c   s   d V }|   | jd tjtjtjtjtjf}||k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   )rp   rK  ro   r<  T)r   )Z
get_resultr   ra   r   ZOKZTESTS_FAILEDZINTERRUPTEDZUSAGE_ERRORZNO_TESTS_COLLECTEDrX   ro   r   pytest_terminal_summaryZ
shouldfailr   rM   _report_keyboardinterruptr   Z
shouldstopsummary_stats)r<   r&  rK  r   Zsummary_exit_codesr>   r>   r?   pytest_sessionfinish#  s&    
z%TerminalReporter.pytest_sessionfinish)NNNc             c   s:   |    |   |   |   d V  |   |   d S )N)summary_errorssummary_failuressummary_warningssummary_passesshort_test_summary)r<   r>   r>   r?   rL  >  s    z(TerminalReporter.pytest_terminal_summary)excinfor8   c             C   s   |j dd| _d S )NT)Zfuncargs)Zgetreprr   )r<   rU  r>   r>   r?   pytest_keyboard_interruptI  s    z*TerminalReporter.pytest_keyboard_interruptc             C   s   | j d k	r|   d S )N)r   rM  )r<   r>   r>   r?   pytest_unconfigureL  s    
z#TerminalReporter.pytest_unconfigurec             C   sv   | j }|d k	st|jd k	s t|jj}| d| d|k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   r  	reprcrashr   r   ro   r}   Z	fulltracer>  r   ra   )r<   r   rv   r>   r>   r?   rM  P  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 )N)r   r8   c                s\   j | } rX| rX|d t   } d}|d dd|d< |d|7 }|S )N[r   r   z::)ro   cwd_relative_nodeidendswithr   r   r   rr   )r   ra   rB   )rZ  r<   r>   r?   mkrelc  s    
z-TerminalReporter._locationline.<locals>.mkrelr   z::r   \z <- z
[location]rq   )	rM   r   r   r   r   ZSEPr$   r   r   )r<   r   r   r   rZ  r^  r   r>   )rZ  r<   r?   r   `  s    
zTerminalReporter._locationlinec             C   s   |j }|r|S dS )Nztest session)	head_line)r<   r  r`  r>   r>   r?   _getfailureheadlinew  s    z$TerminalReporter._getfailureheadlinec             C   sN   yt |jjS  tk
rH   yt |jd d S  tk
rB   dS X Y nX d S )N2   r   )rM   longreprrY  AttributeError)r<   r  r>   r>   r?   _getcrashline}  s    zTerminalReporter._getcrashline)rF  c             C   s   dd | j |dD S )Nc             S   s   g | ]}t |d s|qS )Z	_pdbshown)r  )r  r   r>   r>   r?   r    s    z/TerminalReporter.getreports.<locals>.<listcomp>r>   )r   r   )r<   rF  r>   r>   r?   
getreports  s    zTerminalReporter.getreportsc                s4    dr0 jd}|s d S  jd k	}|r>| jd  }n|}t| _|sTd S i }x |D ]}||jg | q^W tt	 t
d fdd}|rdnd} jd|d	d
d xr| D ]f\}}	||	}
|
r j|
 | }ddd |D }| }n| } j|  j  qW  jd d S )Nr   r0   )reportsr8   c                sr   g }x&| D ]}|  j}|r
|| q
W t|dk rHd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 )z::rD   r   N)rM   r   )r  Zlocr>   r>   r?   rA    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{}rD   r   r   N)r  )r  kvr>   r>   r?   rA    s   )	r   ro   r7  r   rr   rs   rM   r   r   )rg  Z	locationsr   r   Zcounts_by_filename)r<   r>   r?   collapsed_location_report  s    
zDTerminalReporter.summary_warnings.<locals>.collapsed_location_reportzwarnings summary (final)zwarnings summaryr   TF)r   r  r   c             s   s   | ]}d | V  qdS )z  Nr>   )r  r   r>   r>   r?   rA    s    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   r7  r   r   rM   r   r   r   ra   rE  rr   rstrip)r<   Zall_warningsr   Zwarning_reportsZreports_grouped_by_messagewrrk  r   r   Zmessage_reportsZmaybe_locationr3  Zindentedr>   )r<   r?   rR    s:    



z!TerminalReporter.summary_warningsc             C   s   | j jjdkr|| dr|| d}|s*d S | dd xD|D ]<}|jrl| |}| jd|ddd | | | 	|j
 q<W d S )	Nr`   Pr+   r   ZPASSESr  T)r   r  )ro   r}   r^   r   rf  r   sectionsra  _outrep_summary_handle_teardown_sectionsr   )r<   rg  r  rv   r>   r>   r?   rS    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   )r  r   )r   r>   r?   r    s   z:TerminalReporter._get_teardown_reports.<locals>.<listcomp>)rf  )r<   r   rg  r>   )r   r?   _get_teardown_reports  s    

z&TerminalReporter._get_teardown_reportsc             C   s"   x|  |D ]}| | qW d S )N)rr  print_teardown_sections)r<   r   r   r>   r>   r?   rq    s    z*TerminalReporter._handle_teardown_sections)r  r8   c             C   s~   | j jj}|dkrd S xb|jD ]X\}}|dkr8||kr8qd|kr| jd| |dd  dkrj|d d }| j| qW d S )Nr`   rg   r   r)  r;  r   )ro   r}   rc   ro  r   r   ra   )r<   r  rc   secnamer   r>   r>   r?   rs    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r^xb|D ]}| |}| | q@W n@x>|D ]6}| |}| jd|ddd | | | 	|j
 qdW d S )	Nr`   r*   r   ZFAILURESra   r  T)r   r  )ro   r}   r^   rf  r   re  rt   ra  rp  rq  r   )r<   rg  r  ra   rv   r>   r>   r?   rQ    s    





z!TerminalReporter.summary_failuresc             C   s   | j jjdkr| d}|s d S | dd x^| jd D ]P}| |}|jdkrZd| }nd|j d| }| jd	|d
d
d | | q8W d S )Nr`   r1   r   ZERRORSr   zERROR collecting z	ERROR at z of r  T)r   r  )	ro   r}   r^   rf  r   r   ra  r   rp  )r<   rg  r  rv   r>   r>   r?   rP    s    



zTerminalReporter.summary_errorsc             C   s   | | j | jjj}|dkr"d S xZ|jD ]P\}}|dkrD||krDq*| jd| |dd  dkrn|d d }| j| q*W d S )Nr`   rg   r)  r;  r   )r>  r   ro   r}   rc   ro  r   ra   )r<   r  rc   rt  r   r>   r>   r?   rp  	  s    
z TerminalReporter._outrep_summaryc             C   sH  | j dk rd S t | j }|  \}}g }| j dk}|rB| jj}xB|D ]:\}}| jj|f|}	|rx|t|	t| 7 }|	|	 qHW d
|}
|di}dt| }| jj|f|}|r|t|t| 7 }|
|7 }
|r| jjd|}|dr|d d }|t|7 }|
|7 }
|r6| jd	|
fd
|i| n| j|
f| d S )Nr;  r   z, Tz in r   z[0mr   r   )r   )r   r   r  r+  build_summary_stats_liner   r   r   r   r7  rr   format_session_durationr]  r   rt   )r<   Zsession_durationpartsr  Z
line_partsZdisplay_sepr   textr   Zwith_markuprv   Zmain_markupZdurationZduration_with_markupZmarkup_for_end_sepr>   r>   r?   rN    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 }x$ j D ]}||}|r|| qW |r jddddd x|D ]}	 |	 qW d S )N)r3  statr8   c               sX    j |g }|sd S  j}x6|D ].}t|t}t|| j|di}| | q"W d S )NT)r   r   ro   _color_for_type_color_for_type_default _get_line_with_reprcrash_messager   r7  )r3  rz  r*   ro   r  rh   ra   )r<   r>   r?   show_simple?  s    
z8TerminalReporter.short_test_summary.<locals>.show_simple)r3  r8   c                s    j dg }xr|D ]j}| j} jj|ftd di}t j j|}| d| }|j}|rt|dt	| 7 }| 
| qW d S )Nr.   r0   Trq   z - )r   r   _get_verbose_wordro   r   r   r{  _get_node_id_with_markupr   rM   r7  )r3  r.   r  verbose_wordmarkup_wordr   ra   r
  )r<   r>   r?   show_xfailedK  s    
z9TerminalReporter.short_test_summary.<locals>.show_xfailedc                st    j dg }x`|D ]X}| j} jj|ftd di}t j j|}|j}| 	| d| d|  qW d S )Nr/   r0   Trq   )
r   r   r  ro   r   r   r{  r  r   r7  )r3  r/   r  r  r  r   r
  )r<   r>   r?   show_xpassedZ  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td di}d}xf|D ]^\}}}}	|		|r|	t
|d  }	|d k	r| d|||||	f  q\| d||||	f  q\W d S )Nr,   r   r0   Tz	Skipped: z%s [%d] %s:%d: %sz%s [%d] %s: %s)r   r   _folded_skipsr   r  ro   r   r   r{  
startswithr   r7  )
r3  r,   Zfskipsr  r  r   Znumr   r   r
  )r<   r>   r?   show_skippede  s    
z9TerminalReporter.short_test_summary.<locals>.show_skippedr*   )rz  r+   r1   )r   Xfr   pr   r   zshort test summary infoT)r   r  )rZ   r   rM   r   r   r   rt   )
r<   r~  r  r  r  ZREPORTCHAR_ACTIONSr3  r   rU   ra   r>   )r<   r?   rT  ;  s*    



z#TerminalReporter.short_test_summaryc             C   sB   | j d ks| jd ks| jr6|   | j s,t| js6t| j | jfS )N)r   r   r  r   r  )r<   r>   r>   r?   r    s
    

z TerminalReporter._get_main_color)unknown_type_seenr8   c             C   sR   | j }d|ksd|krd}n2d|ks0d|ks0|r6d}nd|k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   sX   g }x0| j  D ]"}|r|tkr||kr|| qW tt| | _| t|| _d S )N)	r   keysKNOWN_TYPESr7  listr   r  rO   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)ro   r   &_build_collect_only_summary_stats_line _build_normal_summary_stats_line)r<   r>   r>   r?   rv    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)rF   )r  r   r>   r>   r?   r    s    z<TerminalReporter._get_reports_to_display.<locals>.<listcomp>)r   r   )r<   r  rg  r>   r>   r?   _get_reports_to_display  s    z(TerminalReporter._get_reports_to_displayc       	      C   s   |   \}}g }xV|D ]N}| |}|rt|}t|t}|dd||ki}|dt|| |f qW |szdtdifg}||fS )NTr  z%d %szno tests ran)r  r  r   r{  r   r|  r7  	pluralize)	r<   r  Zknown_typesrx  r  rg  rS   rh   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 (z%d %s)r   r  r   r  r{  )r<   r-   r   rx  r  Zcollected_outputZall_tests_were_deselectedr%  r>   r>   r?   r    s*    


z7TerminalReporter._build_collect_only_summary_stats_line)N)r   )NN)r   )F)`rI   rJ   rK   r   r   r   r;   r   propertyrk   r   rO   r   rW   rX   r   setterr   rM   r   r   r   r   r   r   r   bytesrt   r   r   r   ra   r   r   r   r   r   r0   WarningMessager   r   r   r!   r   r   r   r'   r  r  r  r  r   r  r  r&   r"  r!  r   r4  r2  r   r1  r?  r=  r   rO  r
   rL  r   BaseExceptionrV  rW  rM  r   ra  re  rf  rR  rS  rr  rq  rs  rQ  rP  r%   rp  rN  rT  r  r  r   r	   rv  r  r  r  r>   r>   r>   r?   ry   ?  s   	 C
%
6%R	**ry   )twro   r  c             C   sF   | |j}|d^}}|r>| jd|dd}|d | S |S d S )Nz::T)r  )r\  r   r   r   rr   )r  ro   r  r   pathrx  Zparts_markupr>   r>   r?   r    s    r  )r  rv   r  r8   c             C   s   | d}|dkr|d| }d}t| d}|t| |krDdS |t| |kr|t|8 }|d| }x |t| |kr|dd }qnW ||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   r  r   )r  rv   r  iZellipsisZformat_widthr>   r>   r?   r    s    
r  )ro   r  r  word_markupr8   c             C   s   | | }|j|f|}t|| |}| d| }t|}y|jjj}	W n tk
r\   Y n:X t s||j	| }
t
d|	|
}	n
d|	 }	|	dk	r||	7 }|S )z?Get summary line for a report, trying to add reprcrash message.rq   z - {}z - N)r  r   r  r   rc  rY  r   rd  r   r   r  )ro   r  r  r  r  r	  r   ra   Z
line_widthrv   r  r>   r>   r?   r}    s     


r}  )r   r,   r8   c             C   s   i }x|D ]}|j d k	stt|j ts6t||j ft|j dksRt||j f|j \}}}t| t|}t|di }|jdkrd|krd|kr|d |f}n
|||f}|	|g 
| q
W g }	x(| D ]\}}
|	
t|
f| qW |	S )Nr(  keywordsr   skipZ
pytestmark)rc  r  r   r   r   r$   r   rF   r   r   r7  r   )r   r,   dZeventr   r   r
  r  r  rB   Zeventsr>   r>   r?   r  :  s$    


r  r   r   r   )r*   r1   r0   r+   )rS   nounr8   c             C   s4   |dkr| |fS | dd}| | dkr.|d n|fS )N)r1   r0   r  r0   ZwarningrD   r   )r   )rS   r  r>   r>   r?   r  b  s    r  )r8   c             C   sN   g }xD| D ]<\}}dj |d}|dr4|dd  }||kr
|| q
W |S )Nz"{dist.project_name}-{dist.version})distzpytest-   )r  r  r7  )r9  rB   r   r  rF  r>   r>   r?   r8  o  s    
r8  )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)datetimeZ	timedeltark   )r  Zdtr>   r>   r?   rw  }  s    rw  c             C   s   t | dr4tt| j}|dr0|tdd }|S | js>tt| j	t
sNt| 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: Nz	Skipped: ZSkippedr   )r  r   rM   r   r  r   r,   r  r   rc  r   )r   r
  r  r>   r>   r?   r    s    



r  )^rL   rP   r  rD  r,  rz   r0   collectionsr   	functoolsr   Zpathlibr   typingr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   attrr.  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  rl   ZActionr2   rn   r   rM   r   r   r   r   ry   r  rk   r  rO   r}  r  r{  r|  r  r8  floatrw  r  r>   r>   r>   r?   <module>   s   
%{       C
"	