U
    42i"                     @  s  d 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ZG dd deZdddddZejddddddZdddddZdddddZddddd Zd!gZdd"dd#d$Zdd"dd%d&ZdS )'z3Version info, help messages, tracing configuration.    )annotations)ActionN)	Generator)Config)ExitCode)	PrintHelp)Parser)TerminalReporterc                      s,   e Zd ZdZd fdd	Zd	ddZ  ZS )

HelpActiona}  An argparse Action that will raise an exception in order to skip the
    rest of the argument parsing when --help is passed.

    This prevents argparse from quitting due to missing required arguments
    when any are defined, for example by ``pytest_addoption``.
    This is similar to the way that the builtin argparse --help option is
    implemented by raising SystemExit.
    NFc                   s   t  j||d|d|d d S )NTr   )option_stringsdestconstdefaultnargshelp)super__init__)selfr   r   r   r   	__class__ 6/tmp/pip-unpacked-wheel-7n2p7kht/_pytest/helpconfig.pyr      s    zHelpAction.__init__c                 C  s&   t || j| j t|jddr"td S )NZafter_preparseF)setattrr   r   getattr_parserr   )r   parser	namespacevaluesoption_stringr   r   r   __call__'   s    zHelpAction.__call__)NFN)N)__name__
__module____qualname____doc__r   r   __classcell__r   r   r   r   r
      s   	
r
   r   None)r   returnc              	   C  s   |  d}|jddddddd |jd	d
tddd |jdddg ddd |jdddddd |jddddddd d! |jd"d#d$dd%d& d S )'NZdebugconfigz	--versionz-Vcountr   versionzoDisplay pytest version and information about plugins. When given twice, also display information about plugins.)actionr   r   r   z-hz--helpr   z(Show help message and configuration info)r)   r   r   z-pappendZpluginsnamezEarly-load given plugin module name or entry point (multi-allowed). To avoid loading of plugins, use the `no:` prefix, e.g. `no:doctest`.)r)   r   r   metavarr   z--traceconfigz--trace-config
store_trueFz)Trace considerations of conftest.py files)r)   r   r   z--debugstore?zpytestdebug.logdebugZDEBUG_FILE_NAMEzStore internal tracing debug information in this log file. This file is opened with 'w' and truncated as a result, care advised. Default: pytestdebug.log.)r)   r   r   r   r,   r   z-oz--override-iniZoverride_iniz^Override ini option with "option=value" style, e.g. `-o xfail_strict=True -o cache_dir=cache`.)r   r)   r   )ZgetgroupZ	addoptionZ
_addoptionr
   )r   groupr   r   r   pytest_addoption/   s^    
	
r2   T)wrapperzGenerator[None, Config, Config]r&   c               
   #  s   d V   j jr j j} t| ddddtjdtt	t
j jjt  jj  jjj  j t
jd|  d dd	 fd
d} |  S )Nwzutf-8)encodingz@versions pytest-{}, python-{}
invocation_dir={}
cwd={}
args={}

.z$writing pytest debug information to 
r%   r4   c                     s6      tjdj d  jjd    d S )Nz"wrote pytest debug information to r8   )closesysstderrwriter+   traceroot	setwriterr   configZ	debugfileZundo_tracingr   r   unset_tracing}   s    z+pytest_cmdline_parse.<locals>.unset_tracing)optionr0   openr<   formatpytest__version__joinmapstrr:   version_infoZinvocation_paramsdirosgetcwdargsr=   r>   r?   pluginmanagerZenable_tracingr;   Zadd_cleanup)pathrB   r   r@   r   pytest_cmdline_parseg   s&    


rR   r   )rA   r&   c                 C  sl   | j jdkrRtjdtj dtj d t| }|rh|D ]}tj|d  q:ntjdtj d d S )N   zThis is pytest version z, imported from r8   zpytest )	rC   r(   r:   stdoutr<   rF   rG   __file__getpluginversioninfo)rA   
plugininfoliner   r   r   showversion   s    rY   zint | ExitCode | Nonec                 C  s@   | j jdkrt|  dS | j jr<|   t|  |   dS d S )Nr   )rC   r(   rY   r   Z_do_configureshowhelpZ_ensure_unconfigure)rA   r   r   r   pytest_cmdline_main   s    r[   c                 C  s  dd l }| jd}|d k	s t|j}|| jj  |	  |	d |	  |j
}d}d| }| jjD  ]}| jj| \}}	}
|	d krd}	|d krtd| | d|	 d	}|d
|  t|}||d kr|	  |j||||dd}|D ]}|	| qql|d|| d   |j||| dd}|rl|	|d  |dd  D ]}|	||  qVql|	  |	d ddddddg}|D ]"\}}|	d
|dd|  q|	  |	  |	d |	d |	d |jdg D ]}|j	d|j dd qd S ) Nr   ZterminalreporterzY[pytest] ini-options in the first pytest.ini|tox.ini|setup.cfg|pyproject.toml file found:    stringz!help argument cannot be None for z (z):     F)initial_indentsubsequent_indentbreak_on_hyphens   )rc   rS   zEnvironment variables:)CIzmWhen set (regardless of value), pytest knows it is running in a CI process and does not truncate summary info)ZBUILD_NUMBERzEquivalent to CI)ZPYTEST_ADDOPTSzExtra command line options)ZPYTEST_PLUGINSz.Comma-separated plugins to load during startup)ZPYTEST_DISABLE_PLUGIN_AUTOLOADz"Set to disable plugin auto-loading)ZPYTEST_DEBUGz1Set to enable debug tracing of pytest's internalsz<24z/to see available markers type: pytest --markersz1to see available fixtures type: pytest --fixturesz(shown according to specified file_or_dir or current dir if not specified; fixtures with leading '_' are only shown with the '-v' optionwarningsz
warning : T)Zred)textwraprP   Z
get_pluginAssertionErrorZ_twr<   r   Z	optparserformat_helprX   Z	fullwidthZ	_ininamesZ_inidict	TypeErrorlenwrapstatsgetmessage)rA   rg   ZreporterZtwcolumnsZ
indent_lenindentr+   r   typer   specZspec_lenZ	helplinesrX   wrappedvarsZwarningreportr   r   r   rZ      sz    


rZ   )Zpytest_pluginszlist of plugin names to loadz	list[str]c                 C  sd   g }| j  }|r`|d |D ]>\}}t|dt|}|j d|j d| }|d|  q |S )Nzregistered third-party plugins:rU   -z at r_   )rP   Zlist_plugin_distinfor*   r   reprproject_namer(   )rA   linesrW   plugindistloccontentr   r   r   rV      s    

rV   c                 C  s   g }| j js| j jr<|dtj  t| }|r<|| | j jr|d | j	 }|D ]:\}}t
|drv|j}nt|}|d|dd|  q\|S )Nzusing: pytest-zactive plugins:rU   z    z<20z: )rC   r0   Ztraceconfigr*   rF   rG   rV   extendrP   Zlist_name_pluginhasattrrU   rw   )rA   ry   Zverinfoitemsr+   rz   rr   r   r   pytest_report_header  s    



r   )r#   
__future__r   argparser   rM   r:   typingr   Z_pytest.configr   r   r   Z_pytest.config.argparsingr   Z_pytest.terminalr	   rF   r
   r2   ZhookimplrR   rY   r[   rZ   Zconftest_optionsrV   r   r   r   r   r   <module>   s*   8
 R