B
    `}              	   @   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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,m0Z0 dd!l,m1Z1 dd"l,m2Z2 dd#l,m3Z3 dd$l,m4Z4 dd%l,m5Z5 dd&l,m6Z6 dd'l,m7Z7 dd(l,m8Z8 dd)l,m9Z9 dd*l:m;Z; dd+l:m<Z< dd,l:m=Z= dd-l>m?Z? dd.l@mAZA dd/lBmCZC dd0lDmEZE dd1lFmGZG dd2lFmHZH dd3lImJZJ dd4lImKZK dd5lImLZL dd6lImMZM dd7lNmOZO dd8lNmPZP dd9lQmRZR dd:lQmSZS dd;lQmTZT dd<lQmUZU dd=lVmWZW dd>lVmXZX erBdd?lYmZZZ dd@lBm[Z[ e?ddAdBdCZ\e;eee]e<f  dDdEdFZ^dGddHdIdJZ_e;ddDdKdLZ`eaddMdNdOZbe=dPdQdReec dSdTdUZdejejfe!jgedV dWdXdYZhejejfeea eidZd[d\ZjejejfdVd]d^d_Zke=dPdQd`eaecdadbdcZlG ddde deZmG dfdg dgZneopeo eqerdhdidjdkheqeneqen Zs[nG dld` d`eme!jgZtG dmdV dVe!juetZvG dndo doevZwddpdqdrZxeceea dsdtduZyG dvdw dwetZzG dxdy dyetZ{eceidzd{d|Z|eceidzd}d~Z}e.G dd dZ~e.G ddG dGZeea eeaee jec  f eeieea f ddddZeeaef ee; eadddZeceae]eeegeec f  eea ee; eadddZe]eHeea eeegeec f  eeedeaf   eea ee; eadddZdeea eeH eeegeec f  eeedeaf   ee; eea eea dddZdd Ze;eEddddZe;ee]e<f dDddZe;eEddddZde)eaeaddddZG ddR dReme!jZG dd deZdS )z7Python test discovery, setup and run of test functions.    N)Counter)defaultdict)partial)Any)Callable)Dict)	Generator)Iterable)Iterator)List)Mapping)Optional)Sequence)Set)Tuple)Type)TYPE_CHECKING)Union)fixtures)nodes)filter_traceback)getfslineno)ExceptionInfo)TerminalRepr)TerminalWriter)saferepr)ascii_escaped)final)get_default_arg_names)get_real_func)	getimfunc)getlocation)is_async_function)is_generator)NOTSET)
REGEX_TYPE)safe_getattr)safe_isclass)STRING_TYPES)Config)ExitCode)hookimpl)Parser)#FSCOLLECTOR_GETHOOKPROXY_ISINITPATH)FuncFixtureInfo)Session)MARK_GEN)ParameterSet)get_unpacked_marks)Mark)MarkDecorator)normalize_mark_list)fail)skip)import_path)ImportPathMismatchError)parts)visit)PytestCollectionWarning)PytestUnhandledCoroutineWarning)Literal)_Scope)parserreturnc             C   s   |  d}|jddddddd |jd	dd
ddd | jddddgdd | jdddgdd | jdddgdd | jddddd d S )NZgeneralz
--fixturesz
--funcargs
store_trueshowfixturesFzishow available fixtures, sorted by plugin appearance (fixtures with leading '_' are only shown with '-v'))actiondestdefaulthelpz--fixtures-per-testshow_fixtures_per_testzshow fixtures per testpython_filesargsz	test_*.pyz	*_test.pyz9glob-style file patterns for Python test module discovery)typerF   rG   python_classesZTestz6prefixes or glob names for Python test class discoverypython_functionstestzDprefixes or glob names for Python test function and method discoveryDdisable_test_id_escaping_and_forfeit_all_rights_to_community_supportboolzcdisable string escape non-ascii characters, might cause unwanted side effects(use at your own risk))ZgetgroupZ	addoptionZaddini)r@   group rR   V/home/kop/projects/devel/pgwui/test_venv/lib/python3.7/site-packages/_pytest/python.pypytest_addoptionP   sD    
rT   )configrA   c             C   s,   | j jrt|  dS | j jr(t|  dS d S )Nr   )optionrC   rH   )rU   rR   rR   rS   pytest_cmdline_main~   s    rW   Metafunc)metafuncrA   c             C   s4   x.| j jddD ]}| j|j|jd|i qW d S )Nparametrize)name_param_mark)
definitioniter_markersrZ   rJ   kwargs)rY   markerrR   rR   rS   pytest_generate_tests   s    ra   c             C   s   |  dd |  dd d S )Nmarkersa  parametrize(argnames, argvalues): call a test function multiple times passing in different arguments in turn. argvalues generally needs to be a list of values if argnames specifies only one name or a list of tuples of values if argnames specifies multiple names. Example: @parametrize('arg1', [1,2]) would lead to two calls of the decorated test function, one with arg1=1 and another with arg1=2.see https://docs.pytest.org/en/stable/parametrize.html for more info and examples.zusefixtures(fixturename1, fixturename2, ...): mark tests as needing all of the specified fixtures. see https://docs.pytest.org/en/stable/fixture.html#usefixtures )Zaddinivalue_line)rU   rR   rR   rS   pytest_configure   s    	rc   )nodeidrA   c             C   sV   d}|d7 }|d7 }|d7 }|d7 }|d7 }|d7 }t t||  tdd	 d S )
NzFasync def functions are not natively supported and have been skipped.
zMYou need to install a suitable plugin for your async framework, for example:
z
  - anyio
z  - pytest-asyncio
z  - pytest-tornasync
z  - pytest-trio
z  - pytest-twistedz?async def function and no async plugin installed (see warnings))msg)warningswarnr=   formatr7   )rd   re   rR   rR   rS   async_warn_and_skip   s    ri   T)ZtrylastFunction)
pyfuncitemrA   c                s`   | j }t|rt| j | j  fdd| jjD }|f |}t|dsRt|dr\t| j dS )Nc                s   i | ]} | |qS rR   rR   ).0arg)funcargsrR   rS   
<dictcomp>   s    z&pytest_pyfunc_call.<locals>.<dictcomp>	__await__	__aiter__T)objr"   ri   rd   rn   _fixtureinfoargnameshasattr)rk   ZtestfunctionZtestargsresultrR   )rn   rS   pytest_pyfunc_call   s    


rw   Module)pathparentrA   c             C   sX   | j }|dkrT|j| s6t| |jddg s6d S |j| }|j| |d}|S d S )Nz.pyrI   z__init__.py)ry   rz   )extsession
isinitpathpath_matches_patternsrU   getinigethookproxypytest_pycollect_makemodule)ry   rz   r{   ihookmodulerR   rR   rS   pytest_collect_file   s    r   )ry   patternsrA   c                s   t  fdd|D S )zKReturn whether path matches any of the patterns in the list of globs given.c             3   s   | ]}  |V  qd S )N)fnmatch)rl   pattern)ry   rR   rS   	<genexpr>   s    z(path_matches_patterns.<locals>.<genexpr>)any)ry   r   rR   )ry   rS   r~      s    r~   )ry   rA   c             C   s.   | j dkrtj|| d}|S tj|| d}|S )Nz__init__.py)fspath)basenamePackagefrom_parentrx   )ry   rz   pkgmodrR   rR   rS   r      s
    
r   PyCollector)	collectorr[   rr   c             C   s   t |r&| ||rtj| ||dS n| ||rt|d|}t|stt|st	|\}}t
jtd| d t||d d nft|ddrt|rtj| |d}d	j|d}|tjd
|d |t| nt| ||}|S d S )N)r[   rr   __func__z/cannot collect %r because it is not a function.   )messagecategoryfilenamelineno__test__T)r[   z?yield tests were removed in pytest 4.0 - {name} will be ignoredF)runreason)r'   istestclassClassr   istestfunctiongetattrinspect
isfunctionr   r   rf   warn_explicitr<   strr#   rj   rh   Z
add_markerr0   Zxfailrg   list_genfunctions)r   r[   rr   r   r   resr   rR   rR   rS   pytest_pycollect_makeitem   s,    r   c               @   s   e Zd ZU dZerpdZeed< dZe	e
j ed< g Zee ed< ee
j e	e
j ddd	Zee
j d
ddZedd Zedd Zedd Zedd Zejdd Zdd ZdeeedddZeeejj ef e!ef d
ddZ"dS )
PyobjMixinT r[   Nrz   own_markers)clsrA   c             C   s   d S )NrR   )selfr   rR   rR   rS   	getparent  s    zPyobjMixin.getparent)rA   c             C   s   d S )NrR   )r   rR   rR   rS   	listchain	  s    zPyobjMixin.listchainc             C   s   |  t}|dk	r|jS dS )z@Python module object this node was collected from (can be None).N)r   rx   rr   )r   noderR   rR   rS   r     s    
zPyobjMixin.modulec             C   s   |  t}|dk	r|jS dS )z?Python class object this node was collected from (can be None).N)r   r   rr   )r   r   rR   rR   rS   r     s    
zPyobjMixin.clsc             C   s   |  t}|dk	r|jS dS )zBPython instance object this node was collected from (can be None).N)r   Instancerr   )r   r   rR   rR   rS   instance  s    
zPyobjMixin.instancec             C   s>   t | dd}|dkr:|   | _}| jr:| jt| j |S )zUnderlying Python object._objN)r   _getobjr   _ALLOW_MARKERSr   extendr2   rr   )r   rr   rR   rR   rS   rr     s    zPyobjMixin.objc             C   s
   || _ d S )N)r   )r   valuerR   rR   rS   rr   *  s    c             C   s"   | j dk	st| j j}t|| jS )zCGet the underlying Python object. May be overwritten by subclasses.N)rz   AssertionErrorrr   r   r[   )r   rr   rR   rR   rS   r   .  s    zPyobjMixin._getobjF)stopatmoduleincludemodulerA   c             C   s~   |   }|  g }xV|D ]N}t|tr*q|j}t|tr^tj|d }|r^|r\|	| P |	| qW |  d
|S )z5Return Python path relative to the containing module.r   .)r   reverse
isinstancer   r[   rx   osry   splitextappendjoin)r   r   r   chainr:   r   r[   rR   rR   rS   
getmodpath5  s     



zPyobjMixin.getmodpathc             C   sv   | j }t|dd }t|trJtj|j j}|dr@|d d }|}|}nt	|\}}| 
 }t|tslt|||fS )Ncompat_co_firstlinenoz.pyc)rr   r   r   intsysmodules
__module____file__endswithr   r   r   )r   rr   r   	file_pathr   r   ZmodpathrR   rR   rS   
reportinfoH  s    

zPyobjMixin.reportinfo)TF)#__name__r   __qualname__r   r   r[   r   __annotations__rz   r   r   Noder   r   r3   r   Z	_NodeTyper   r   propertyr   r   r   rr   setterr   rP   r   r   r   pyry   localr   r   rR   rR   rR   rS   r      s   
r   c               @   s   e Zd ZdS )_EmptyClassN)r   r   r   rR   rR   rR   rS   r   ^  s    r   Zempty_module__builtins__r   
__cached__c               @   s   e Zd ZeedddZeedddZeedddZeeed	d
dZ	eeed	ddZ
eeedddZeeejejf  dddZeed dddZdS )r   )r[   rA   c             C   s   |  d|S )NrM   )_matches_prefix_or_glob_option)r   r[   rR   rR   rS   funcnamefiltero  s    zPyCollector.funcnamefilter)rr   rA   c             C   s   t |dddkS )zgLook for the __test__ attribute, which is applied by the
        @nose.tools.istest decorator.
        r   FT)r&   )r   rr   rR   rR   rS   
isnosetestr  s    zPyCollector.isnosetestc             C   s   |  d|S )NrL   )r   )r   r[   rR   rR   rS   classnamefilter{  s    zPyCollector.classnamefilter)rr   r[   rA   c             C   sL   |  |s| |rDt|tr*t|dd}t|ddoBt|d kS dS d S )Nr   F__call__)r   r   r   staticmethodr&   r   getfixturemarker)r   rr   r[   rR   rR   rS   r   ~  s    
zPyCollector.istestfunctionc             C   s   |  |p| |S )N)r   r   )r   rr   r[   rR   rR   rS   r     s    zPyCollector.istestclass)option_namer[   rA   c             C   sP   xJ| j |D ]:}||r dS d|ks8d|ks8d|krt||rdS qW dS )z`Check if the given name matches the prefix or glob-pattern defined
        in ini configuration.T*?[F)rU   r   
startswithr   )r   r   r[   rV   rR   rR   rS   r     s    
z*PyCollector._matches_prefix_or_glob_option)rA   c             C   s   t | jddsg S t | jdi g}x| jjjD ]}||j q.W t }g }| j}x|D ]x}xrt|	 D ]b\}}|t
kr|qj||krqj|| |j| ||d}	|	d krqjqjt|	tr||	 qj||	 qjW qXW dd }
|j|
d |S )Nr   T__dict__)r   r[   rr   c             S   s   |   \}}}t||fS )N)r   r   )itemr   r   _rR   rR   rS   sort_key  s    z%PyCollector.collect.<locals>.sort_key)key)r   rr   	__class____mro__r   r   setr   r   itemsIGNORED_ATTRIBUTESaddr   r   r   sort)r   ZdictsZbaseclsseenvaluesr   Zdicr[   rr   r   r   rR   rR   rS   collect  s2    


zPyCollector.collectrj   c          
   c   s,  |  t}|d k	st|j}|  t}|r0|jp2d }| jj}tj| ||d}|j	}	t
||	| j||d}
g }t|dr||j |d k	rt|dr|| j | jj|t|
d |
jstj| ||	dV  nXt| |
| |	  x@|
jD ]6}| d|j d}tj| ||||	|jdi|d	V  qW d S )
N)r[   callobj)r   r   ra   )rY   )r[   fixtureinfor   ]T)r[   callspecr   r   keywordsoriginalname)r   rx   r   rr   r   r|   _fixturemanagerFunctionDefinitionr   rs   rX   rU   ru   r   ra   r   Z
call_extradict_callsrj   r   Zadd_funcarg_pseudo_fixture_defZprune_dependency_treeid)r   r[   funcobjZ	modulecolr   Zclscolr   fmr]   r   rY   methodsr   subnamerR   rR   rS   r     s<    


zPyCollector._genfunctionsN)r   r   r   r   rP   r   objectr   r   r   r   r   r	   r   r   Item	Collectorr   r
   r   rR   rR   rR   rS   r   n  s   	&c                   sb   e Zd ZdZdd Zeeejej	f  d fddZ
dddd	Zddd
dZdd Z  ZS )rx   z)Collector for test classes and functions.c             C   s   |   S )N)_importtestmodule)r   rR   rR   rS   r     s    zModule._getobj)rA   c                s(   |    |   | jj|  t  S )N)_inject_setup_module_fixture_inject_setup_function_fixturer|   r   parsefactoriessuperr   )r   )r   rR   rS   r     s    zModule.collectNc                sj   t | jd t | jd dkr,dkr,dS tjddd| jj dtd d	 fd
d}|| j_dS )a'  Inject a hidden autouse, module scoped fixture into the collected module object
        that invokes setUpModule/tearDownModule if either or both are available.

        Using a fixture to invoke this methods ensures we play nicely and unsurprisingly with
        other fixtures (#517).
        )setUpModulesetup_module)tearDownModuleteardown_moduleNTr   Zxunit_setup_module_fixture_)autousescoper[   )NNN)rA   c             3   s2    d k	rt  | j d V  d k	r.t | j d S )N)_call_with_optional_argumentr   )request)r
  r  rR   rS   xunit_setup_module_fixture  s
    zGModule._inject_setup_module_fixture.<locals>.xunit_setup_module_fixture)_get_first_non_fixture_funcrr   r   fixturer   r   Z_Module__pytest_setup_module)r   r  rR   )r
  r  rS   r    s    

z#Module._inject_setup_module_fixturec                sj   t | jd t | jd dkr,dkr,dS tjddd| jj dtd d	 fd
d}|| j_dS )a/  Inject a hidden autouse, function scoped fixture into the collected module object
        that invokes setup_function/teardown_function if either or both are available.

        Using a fixture to invoke this methods ensures we play nicely and unsurprisingly with
        other fixtures (#517).
        )setup_function)teardown_functionNTfunctionZxunit_setup_function_fixture_)r  r  r[   )NNN)rA   c             3   sF   | j d k	rd V  d S  d k	r(t | j d V  d k	rBt| j d S )N)r   r  r  )r  )r  r  rR   rS   xunit_setup_function_fixture*  s    
zKModule._inject_setup_function_fixture.<locals>.xunit_setup_function_fixture)r  rr   r   r  r   r   Z_Module__pytest_setup_function)r   r  rR   )r  r  rS   r    s    
z%Module._inject_setup_function_fixturec          
   C   s\  | j d}yt| j|d}W n( tk
rZ } z| t jdd|W d d }~X Y n t	k
r } z| d|j
 |W d d }~X Y n tk
r } zdt }| j ddk r|jt|_|jr|jddn| }t|}| dj| j|d	|W d d }~X Y n< tjk
rH } z|jr, | d
|W d d }~X Y nX | j j| |S )Nz--import-mode)modeshort)stylezimport file mismatch:
imported module %r has this __file__ attribute:
  %s
which is not the same as the test file we want to collect:
  %s
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modulesverbose   zImportError while importing test module '{fspath}'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
{traceback})r   	tracebackzUsing pytest.skip outside of a test is not allowed. To decorate a test function, use the @pytest.mark.skip or @pytest.mark.skipif decorators instead, and to skip a module use `pytestmark = pytest.mark.{skip,skipif}.)rU   	getoptionr8   r   SyntaxErrorZCollectErrorr   Zfrom_currentZgetreprr9   rJ   ImportErrorr  filterr   Zexconlyr   rh   r7   	ExceptionZallow_module_levelpluginmanagerZconsider_module)r   Z
importmoder   eexc_infoZexc_reprZformatted_tbrR   rR   rS   r  >  s>    zModule._importtestmodule)r   r   r   __doc__r   r	   r   r   r  r  r   r  r  r  __classcell__rR   rR   )r   rS   rx     s   " "c               @   s   e Zd ZdejjejddddZddddZ	ejjdd	d
Z
ejjedddZdedddZdejjeeej dddZeeejejf  dddZdS )r   N)r   rz   rA   c             C   s6   |j }tjj| |||||d tjt|j| _	d S )N)rz   rU   r|   rd   )
r|   r   ZFSCollector__init__r   ry   r   r   dirnamer[   )r   r   rz   rU   r|   rd   rR   rR   rS   r(  o  s    zPackage.__init__)rA   c             C   sP   t | jd}|d k	r t|| j t | jd}|d k	rLtt|| j}| | d S )N)r	  r
  )r  r  )r  rr   r  r   Zaddfinalizer)r   r
  r  funcrR   rR   rS   setup  s    

zPackage.setup)r   c             C   s   t jtdd | j|S )Nr  )
stacklevel)rf   rg   r-   r|   r   )r   r   rR   rR   rS   r     s    zPackage.gethookproxy)ry   rA   c             C   s   t jtdd | j|S )Nr  )r,  )rf   rg   r-   r|   r}   )r   ry   rR   rR   rS   r}     s    zPackage.isinitpathzos.DirEntry[str])direntryrA   c                sj   |j dkrdS tj|j | j  }|j | jdr@dS | j	d}t
 fdd|D rfdS dS )N__pycache__F)ry   rU   Znorecursedirsc             3   s   | ]} j |d V  qdS ))r   N)check)rl   pat)ry   rR   rS   r     s    z#Package._recurse.<locals>.<genexpr>T)r[   r   ry   r   r|   r   dirpathpytest_ignore_collectrU   r   r   )r   r-  r   ZnorecursepatternsrR   )ry   rS   _recurse  s    
zPackage._recurseT)ry   handle_dupesrA   c             C   s   |  s(td|| | | | j|}| j|sT|j	|| j
drTdS |r| j
d}|s| j
jj}||kr~dS || |j|| dS )Nz9{!r} is not a file (isdir={!r}, exists={!r}, islink={!r}))ry   rU   rR   keepduplicates)ry   rz   )isfiler   rh   isdirexistsislinkr|   r   r}   r2  rU   r  r#  Z_duplicatepathsr   r   )r   ry   r4  r   r5  Zduplicate_pathsrR   rR   rS   _collectfile  s    


zPackage._collectfilec             #   s   | j  }|d}|jddrBt|| jdrBtj| |dV  t	 }xt
t|| jdD ]}tj|j| r|jdkr |krq\t|j t fdd|D rq\| r| E d H  q\| sq\q\djddr\| q\W d S )	Nz__init__.pyr   )filerI   )r   )Zrecursec             3   s(   | ] }t | ko|d kV  qdS )z__init__.pyN)r   r   )rl   Z
pkg_prefix)parts_ry   rR   rS   r     s   z"Package.collect.<locals>.<genexpr>)r   r1  r   r/  r~   rU   r   rx   r   r   r;   r   r3  r   ry   r   is_filer[   r:   r   r:  is_dirr   )r   Z	this_pathZinit_moduleZpkg_prefixesr-  rR   )r<  ry   rS   r     s,    



zPackage.collect)NNN)T)r   r   r   r   ry   r   r   r  r(  r+  r   rP   r}   r3  r   r:  r	   r   r  r   rR   rR   rR   rS   r   n  s     	
r   )rA   c             C   s2   | j j}t| r|d8 }|r(| | n|   dS )zyCall the given function with the given argument if func accepts one argument, otherwise
    calls func without arguments.r   N)__code__co_argcountr   ismethod)r*  rm   	arg_countrR   rR   rS   r    s    

r  )rr   namesc             C   s8   x2|D ]*}t | |d}|dk	rt|dkr|S qW dS )zReturn the attribute from the given object to be used as a setup/teardown
    xunit-style function, but only if not marked as a fixture to avoid calling it twice.N)r   r   r   )rr   rC  r[   methrR   rR   rS   r    s    
r  c                   sd   e Zd ZdZedd fdd
Zeeej	ej
f  dddZddd	d
ZddddZ  ZS )r   zCollector for test methods.N)rr   c               s   t  j||dS )zThe public constructor.)r[   rz   )r  r   )r   rz   r[   rr   )r   rR   rS   r     s    zClass.from_parent)rA   c             C   s   t | jddsg S t| jrL| jd k	s*t| td| jj| jjf  g S t	| jr| jd k	sdt| td| jj| jjf  g S | 
  |   tj| ddgS )Nr   TzMcannot collect test class %r because it has a __init__ constructor (from: %s)zLcannot collect test class %r because it has a __new__ constructor (from: %s)z())r[   )r&   rr   hasinitrz   r   rg   r<   r   rd   hasnew_inject_setup_class_fixture_inject_setup_method_fixturer   r   )r   rR   rR   rS   r     s&    

zClass.collectc                sn   t  jdt jdddkr.dkr.dS tjddd jj dtd d	 fd
d}| j_dS )a%  Inject a hidden autouse, class scoped fixture into the collected class object
        that invokes setup_class/teardown_class if either or both are available.

        Using a fixture to invoke this methods ensures we play nicely and unsurprisingly with
        other fixtures (#517).
        )setup_classteardown_classNTclassZxunit_setup_class_fixture_)r  r  r[   )NNN)rA   c             3   sB   d k	rt }t| j d V  d k	r>t }t| j d S )N)r    r  rr   )r   r*  )r   rI  rJ  rR   rS   xunit_setup_class_fixture"  s    zDClass._inject_setup_class_fixture.<locals>.xunit_setup_class_fixture)r  rr   r   r   r  r   r   Z_Class__pytest_setup_class)r   rL  rR   )r   rI  rJ  rS   rG    s    	z!Class._inject_setup_class_fixturec                sl   t | jd t| jdd dkr.dkr.dS tjddd| jj dtd d	 fd
d}|| j_dS )a*  Inject a hidden autouse, function scoped fixture into the collected class object
        that invokes setup_method/teardown_method if either or both are available.

        Using a fixture to invoke this methods ensures we play nicely and unsurprisingly with
        other fixtures (#517).
        )setup_methodteardown_methodNTr  Zxunit_setup_method_fixture_)r  r  r[   )NNN)rA   c             3   sH   |j } d k	r"t| d}t|| d V  d k	rDt| d}t|| d S )NrM  rN  )r  r   r  )r   r  methodr*  )rM  rN  rR   rS   xunit_setup_method_fixture?  s    


zFClass._inject_setup_method_fixture.<locals>.xunit_setup_method_fixture)r  rr   r   r   r  r   r   Z_Class__pytest_setup_method)r   rP  rR   )rM  rN  rS   rH  3  s    
z"Class._inject_setup_method_fixture)r   r   r   r&  classmethodr   r	   r   r   r  r  r   rG  rH  r'  rR   rR   )r   rS   r     s   r   c                   sF   e Zd ZdZdd Zeeejej	f  d fddZ
dd Z  ZS )	r   Fc             C   s   | j d k	st| j j}| S )N)rz   r   rr   )r   rr   rR   rR   rS   r   X  s    zInstance._getobj)rA   c                s   | j j|  t  S )N)r|   r   r  r  r   )r   )r   rR   rS   r   ^  s    zInstance.collectc             C   s   |   | _| jS )N)r   rr   )r   rR   rR   rS   newinstanceb  s    
zInstance.newinstance)r   r   r   r   r   r	   r   r   r  r  r   rR  r'  rR   rR   )r   rS   r   R  s   "r   )rr   rA   c             C   s   t | dd }|r|tjkS dS )Nr(  F)r   r  r(  )rr   initrR   rR   rS   rE  g  s    
rE  c             C   s   t | dd }|r|tjkS dS )N__new__F)r   r  rT  )rr   newrR   rR   rS   rF  n  s    
rF  c            	   @   s   e Zd ZdddddZd dddZedd	d
dZeedddZe	edddZ
eedf ee ee eeeeef  eeddddZdS )	CallSpec2rX   N)rY   rA   c             C   s.   || _ i | _g | _i | _i | _g | _i | _d S )N)rY   rn   _idlistparams_arg2scopenummarksindices)r   rY   rR   rR   rS   r(  w  s    zCallSpec2.__init__)rA   c             C   s`   t | j}|j| j |j| j |j| j |j| j |j| j t	| j
|_
|S )N)rV  rY   rn   updaterX  rZ  r   r[  rY  r   rW  )r   csrR   rR   rS   copy  s    
zCallSpec2.copy)rm   rA   c             C   s&   || j ks|| jkr"td|d S )Nz
duplicate )rX  rn   
ValueError)r   rm   rR   rR   rS   _checkargnotcontained  s    zCallSpec2._checkargnotcontained)r[   rA   c          
   C   s<   y
| j | S  tk
r6 } zt||W d d }~X Y nX d S )N)rX  KeyErrorr_  )r   r[   r$  rR   rR   rS   getparam  s    
zCallSpec2.getparamc             C   s   d tt| jS )N-)r   mapr   rW  )r   rR   rR   rS   r     s    zCallSpec2.idzLiteral['params', 'funcargs'])valtypesrt   valsetr   rZ  scopenumparam_indexrA   c             C   s   xvt ||D ]h\}}	| | || }
|
dkr:|	| j|< n&|
dkrN|	| j|< nds`td|
 || j|< || j|< qW | j| | j	
t| d S )NrX  rn   FzUnhandled valtype for arg: )zipr`  rX  rn   r   r[  rY  rW  r   rZ  r   r5   )r   re  rt   rf  r   rZ  rg  rh  rm   valZvaltype_for_argrR   rR   rS   	setmulti2  s    


zCallSpec2.setmulti2)r   r   r   r(  r^  r   r`  r  rb  r   r   r   r   r	   r   r3   r4   r   rk  rR   rR   rR   rS   rV  u  s   


rV  c               @   s~  e Zd ZdZddejeddddZdddee	e
e	 ee	d	f f eeeee ef  eeee	 f eeeede	eeef  eegee f f  d
ee ddddZee	 eeeede	eeef  eegee f f  ee e	e
e	 dddZeede	eeef  ee e	e
ede	f  dddZee	 eeee	 f ee	df dddZee	 eeee	 f ddddZdS )rX   a  Objects passed to the :func:`pytest_generate_tests <_pytest.hookspec.pytest_generate_tests>` hook.

    They help to inspect a test function and to generate tests according to
    test configuration or values specified in the class or module where a
    test function is defined.
    Nr   )r]   r   rU   rA   c             C   s:   || _ || _|| _|j| _|j| _|| _g | _|j	| _
d S )N)r]   rU   r   rr   r  names_closurefixturenamesr   r   name2fixturedefs_arg2fixturedefs)r   r]   r   rU   r   r   rR   rR   rS   r(    s    	zMetafunc.__init__F)r\   .zOptional[_Scope])rt   	argvaluesindirectidsr  r\   rA   c            C   sR  ddl m} tj||| j| j| jjd\}}~d|krBtddd |dkrXt	|| j
|}| || | ||}	|r|jr|jj}
|
dk	r|
}| j|||| jjd}|r|jr|
dkrt|jd	| ||d
| jj d}g }xf| jpt| gD ]R}xLtt||D ]:\}\}}| }||	||j||j|| || qW qW || _dS )a
  Add new invocations to the underlying test function using the list
        of argvalues for the given argnames.  Parametrization is performed
        during the collection phase.  If you need to setup expensive resources
        see about setting indirect to do it rather at test setup time.

        :param argnames:
            A comma-separated string denoting one or more argument names, or
            a list/tuple of argument strings.

        :param argvalues:
            The list of argvalues determines how often a test is invoked with
            different argument values.

            If only one argname was specified argvalues is a list of values.
            If N argnames were specified, argvalues must be a list of
            N-tuples, where each tuple-element specifies a value for its
            respective argname.

        :param indirect:
            A list of arguments' names (subset of argnames) or a boolean.
            If True the list contains all names from the argnames. Each
            argvalue corresponding to an argname in this list will
            be passed as request.param to its respective argname fixture
            function so that it can perform more expensive setups during the
            setup phase of a test rather than at collection time.

        :param ids:
            Sequence of (or generator for) ids for ``argvalues``,
            or a callable to return part of the id for each argvalue.

            With sequences (and generators like ``itertools.count()``) the
            returned ids should be of type ``string``, ``int``, ``float``,
            ``bool``, or ``None``.
            They are mapped to the corresponding index in ``argvalues``.
            ``None`` means to use the auto-generated id.

            If it is a callable it will be called for each entry in
            ``argvalues``, and the return value is used as part of the
            auto-generated id for the whole set (where parts are joined with
            dashes ("-")).
            This is useful to provide more specific ids for certain items, e.g.
            dates.  Returning ``None`` will use an auto-generated id.

            If no ids are provided they will be generated automatically from
            the argvalues.

        :param scope:
            If specified it denotes the scope of the parameters.
            The scope is used for grouping tests by parameter instances.
            It will also override any fixture-function defined scope, allowing
            to set a dynamic scope using test context or configuration.
        r   )scope2index)rd   r  zK'request' is a reserved name and cannot be used in @pytest.mark.parametrizeF)pytraceN_param_ids_generatedzparametrize() call in )descr)_pytest.fixturesrs  r1   Z_for_parametrizer  rU   r]   rd   r6   _find_parametrized_scopero  _validate_if_using_arg_names_resolve_arg_value_typesZ_param_ids_fromru  _resolve_arg_idsr  __setattr__r   r   rV  	enumerateri  r^  rk  r   rZ  r   )r   rt   rp  rq  rr  r  r\   rs  
parametersZarg_values_typesZgenerated_idsrg  Znewcallsr   rh  Zparam_idZ	param_setZnewcallspecrR   rR   rS   rZ     sP    C
zMetafunc.parametrize)rt   rr  r~  rd   rA   c             C   sP   |dkrd}d}n(t |r$|}d}nd}| ||| jj}t||||| j|dS )a,  Resolve the actual ids for the given argnames, based on the ``ids`` parameter given
        to ``parametrize``.

        :param List[str] argnames: List of argument names passed to ``parametrize()``.
        :param ids: The ids parameter of the parametrized call (see docs).
        :param List[ParameterSet] parameters: The list of parameter values, same size as ``argnames``.
        :param str str: The nodeid of the item that generated this parametrized call.
        :rtype: List[str]
        :returns: The list of ids for each argname given.
        N)rd   )callable_validate_idsr  r   idmakerrU   )r   rt   rr  r~  rd   idfnZids_rR   rR   rS   r{  X  s    zMetafunc._resolve_arg_ids)rr  r~  	func_namerA   c       
      C   s  yt |}W nV tk
rb   yt| W n, tk
rT } ztd|W d d }~X Y nX t |}Y nX |t |kr|dkrd}t||t ||dd g }x~tt||D ]j\}}	|	d kst|	t	r|
|	 qt|	tttfr|
t	|	 qd}t||t|	t|	|dd qW |S )Nz%ids must be a callable or an iterabler   zDIn {}: {} parameter sets specified, with different number of ids: {}F)rt  zTIn {}: ids must be list of string/float/int/bool, found: {} (type: {!r}) at index {})len	TypeErroriterr6   rh   r}  	itertoolsislicer   r   r   floatr   rP   r   rK   )
r   rr  r~  r  Znum_idsr$  re   Znew_idsidxZid_valuerR   rR   rS   r  y  s,    zMetafunc._validate_idszLiteral['params', 'funcargs'])rt   rq  rA   c             C   s   t |tr t||rdnd}nnt |trnt|d}xV|D ],}||kr`td| jj|dd d||< q<W n tdjt	|j| jjddd |S )a  Resolve if each parametrized argument must be considered a
        parameter to a fixture or a "funcarg" to the function, based on the
        ``indirect`` parameter of the parametrized() call.

        :param List[str] argnames: List of argument names passed to ``parametrize()``.
        :param indirect: Same as the ``indirect`` parameter of ``parametrize()``.
        :rtype: Dict[str, str]
            A dict mapping each arg name to either:
            * "params" if the argname should be the parameter of a fixture of the same name.
            * "funcargs" if the argname should be a parameter to the parametrized test function.
        rX  rn   z*In {}: indirect fixture '{}' doesn't existF)rt  z@In {func}: expected Sequence or boolean for indirect, got {type})rK   r*  )
r   rP   r   fromkeysr   r6   rh   r  r   rK   )r   rt   rq  re  rm   rR   rR   rS   rz    s"    



z!Metafunc._resolve_arg_value_typesc          	   C   s   t t| j}| jj}x||D ]t}|| jkr||krHtd||dd qt|trd||kr^dnd}n|rldnd}td| d| d| d	dd qW d
S )a4  Check if all argnames are being used, by default values, or directly/indirectly.

        :param List[str] argnames: List of argument names passed to ``parametrize()``.
        :param indirect: Same as the ``indirect`` parameter of ``parametrize()``.
        :raises ValueError: If validation fails.
        zCIn {}: function already takes an argument '{}' with a default valueF)rt  r  argumentzIn z: function uses no z ''N)	r   r   r  r   rm  r6   rh   r   r   )r   rt   rq  Zdefault_arg_namesr  rm   r[   rR   rR   rS   ry    s    	



z%Metafunc._validate_if_using_arg_names)NN)FNN)r   r   r   r&  r   r.   r)   r(  r   r   r   r   r	   r1   r   r  rP   r   r  r   r   r   r3   rZ   r{  r  r   rz  ry  rR   rR   rR   rS   rX     s2    
  vt!%zfixtures._Scope)rt   arg2fixturedefsrq  rA   c                sn   t |trt|t k}nt|}|rj|p.i } fdd| D }|rjxttjD ]}||krV|S qVW dS )a}  Find the most appropriate scope for a parametrized call based on its arguments.

    When there's at least one direct argument, always use "function" scope.

    When a test function is parametrized and all its arguments are indirect
    (e.g. fixtures), return the most narrow scope based on the fixtures used.

    Related to issue #1832, based on code posted by @Kingdread.
    c                s"   g | ]\}}| kr|d  j qS )r   )r  )rl   r[   
fixturedef)rt   rR   rS   
<listcomp>  s   z,_find_parametrized_scope.<locals>.<listcomp>r  )r   r   r  rP   r   reversedr   Zscopes)rt   r  rq  Zall_arguments_are_fixturesfixturedefsZused_scopesr  rR   )rt   rS   rx    s    

rx  )rj  rU   rA   c             C   s(   |d krd}n
| d}|r | S t| S )NFrO   )r   r   )rj  rU   Zescape_optionrR   rR   rS   _ascii_escaped_by_config  s
    r  )rj  argnamer  r  rd   rU   rA   c          
   C   s.  |rvy|| }|d k	r|} W q t k
rr } z8|d k	r@| dnd}d}	||	|| }	t|	|W d d }~X Y qX n|r|jj|| |d}
|
r|
S t| trt| |S | d kst| tt	t
frt| S t| trt| jS | tkrn8t| tj rt| S tt| dd trt| d}|S t|t| S )Nz: r   zJerror raised while trying to determine id of parameter '{}' at position {})rU   rj  r  r   )r"  rh   r_  hookZpytest_make_parametrize_idr   r(   r  r  r   rP   r   r%   r   r   r$   enumEnumr   )rj  r  r  r  rd   rU   Zgenerated_idr$  prefixre   Zhook_idr[   rR   rR   rS   _idval  s:    




r  )r  parametersetrt   r  rr  rd   rU   rA   c       	         sp   |j d k	r|j S |d ks$t|kr(d n| }|d krb fddt|j|D }d|S t| S d S )Nc          
      s$   g | ]\}}t || d qS ))rd   rU   )r  )rl   rj  r  )rU   r  r  rd   rR   rS   r  L  s   z_idvalset.<locals>.<listcomp>rc  )r   r  ri  r   r   r  )	r  r  rt   r  rr  rd   rU   r   Zthis_idrR   )rU   r  r  rd   rS   	_idvalset>  s    	
 
r  )rt   parametersetsr  rr  rU   rd   rA   c                s    fddt |D }t|}t|t|krt|}tt}	xDt |D ]8\}
}|| dkrPd||	| ||
< |	|  d7  < qPW |S )Nc                s&   g | ]\}}t || d qS ))rU   rd   )r  )rl   Zvalindexr  )rt   rU   r  rr  rd   rR   rS   r  ]  s   zidmaker.<locals>.<listcomp>r   z{}{})r}  r   r  r   r   r   rh   )rt   r  r  rr  rU   rd   Zresolved_idsZ
unique_idsZtest_id_countsZtest_id_suffixesindexZtest_idrR   )rt   rU   r  rr  rd   rS   r  T  s    	r  c             C   s   ddl m} || tS )Nr   )wrap_session)_pytest.mainr  _show_fixtures_per_test)rU   r  rR   rR   rS   rH   v  s    rH   )rU   r|   rA   c                s   dd l }|  tj  |j| | d fddtj	t
 d dfddtjd dfd	d
}x|jD ]}|| q|W d S )Nr   r  c                s    t | t } tj|S )N)r!   r   bestrelpathr   ry   r   )r*  loc)curdirrR   rS   get_best_relpath  s    z1_show_fixtures_per_test.<locals>.get_best_relpath)fixture_defrA   c                s~   | j }dkr|drd S dkr> | j}| d| }n|}j|dd t| j}|rlt| njddd d S )Nr   r   z -- T)greenz    no docstring available)red)r  r   r*  liner   getdocwrite_docstring)r  r  bestrelZfuncargspecZfixture_doc)r  twr  rR   rS   write_fixture  s    
z._show_fixtures_per_test.<locals>.write_fixture)r   rA   c                s   t | dd }|d ks|jsd S   dd| j  dd | j x8t|j D ]&\}}|d k	svt	|s|qb|d  qbW d S )Nrs   rc  zfixtures used by z({})r   )
r   rn  r  sepr[   rh   r  sortedr   r   )r   infor   r  )r  r  r  rR   rS   
write_item  s    z+_show_fixtures_per_test.<locals>.write_item)_pytest.configperform_collectr   ry   r   rU   create_terminal_writergetvaluer   
FixtureDefr  r   r  r   )rU   r|   _pytestr  Zsession_itemrR   )r  r  r  r  r  rS   r  |  s    

r  c             C   s   ddl m} || tS )Nr   )r  )r  r  _showfixtures_main)rU   r  rR   rR   rS   rC     s    rC   c             C   s  dd l }|  tj }|j| }| d}|j}g }t	 }x|j
 D ]\}	}
|
d k	s`t|
sfqLxj|
D ]b}t|jt|}|j|f|krql||j|f |t|j|jj|tj||j|f qlW qLW |  d }x|D ]\}}}}	}||kr,|ds,|  |dd|  |}|dkrF|	d dkrFq|j|	dd |jd	krt|jd
|j dd |dkr|jd| dd |d t|jt|}t|j}|rt|| n|jd| ddd |  qW d S )Nr   r  z_pytest.rc  zfixtures defined from r   T)r  r  z [%s scope])Zcyanz -- %s)Zyellow
z    z: no docstring available)r  ) r  r  r   ry   r   rU   r  r  r   r   ro  r   r   r!   r*  r   r  r   r   r  baseidr   r  r   r   r  r  writer  r   r  r  )rU   r|   r  r  r  r  r   	availabler   r  r  r  r  Zcurrentmoduler  r   r  docrR   rR   rS   r    sZ    





r      )r  r  indentrA   c             C   s&   x | dD ]}| ||  qW d S )Nr  )splitr  )r  r  r  r  rR   rR   rS   r    s    r  c            	       s   e Zd ZdZdZddeddddfeee ee	 ee
 ee ee dd fddZe fddZdd	d
dZedd Zdd Zedd Zdd	ddZdd	ddZee ddddZee eeef dddZ  ZS )rj   a  An Item responsible for setting up and executing a Python test function.

    param name:
        The full function name, including any decorations like those
        added by parametrization (``my_func[my_param]``).
    param parent:
        The parent Node.
    param config:
        The pytest Config object.
    param callspec:
        If given, this is function has been parametrized and the callspec contains
        meta information about the parametrization.
    param callobj:
        If given, the object which will be called when the Function is invoked,
        otherwise the callobj will be obtained from ``parent`` using ``originalname``.
    param keywords:
        Keywords bound to the function object for "-k" matching.
    param session:
        The pytest Session object.
    param fixtureinfo:
        Fixture information already resolved at this fixture node..
    param originalname:
        The attribute name to use for accessing the underlying function object.
        Defaults to ``name``. Set this if name is different from the original name,
        for example when it contains decorations like those added by parametrization
        (``my_func[my_param]``).
    FN)r[   rU   r   r|   r   r   rA   c
                s   t  j||||d |tk	r"| _|	p(| _ j jj  j	t
 j |r| _x|jD ]}
|
 j|
j< q`W  j	t|j |r j|  j fdd  D  |d krֈ jjj  j jdd}| _|j _   d S )N)rU   r|   c                s    i | ]}|j  jkrd |j qS )T)r[   r   )rl   mark)r   rR   rS   ro   A  s   z%Function.__init__.<locals>.<dictcomp>T)rn   )r  r(  r$   rr   r   r   r\  r   r   r   r2   r   rZ  r[   r5   r^   r|   r   Zgetfixtureinfor   rs   rl  rm  _initrequest)r   r[   rz   rU   r   r   r   r|   r   r   r  )r   )r   rS   r(    s,    

zFunction.__init__c                s   t  jf d|i|S )zThe public constructor.rz   )r  r   )r   rz   kw)r   rR   rS   r   P  s    zFunction.from_parent)rA   c             C   s   i | _ tj| dd| _d S )NT)Z	_ispytest)rn   r   ZFixtureRequest_request)r   rR   rR   rS   r  U  s    zFunction._initrequestc             C   s
   t | jS )z$Underlying python 'function' object.)r    rr   )r   rR   rR   rS   r  Y  s    zFunction.functionc             C   s   | j d k	stt| j j| jS )N)rz   r   r   rr   r   )r   rR   rR   rS   r   ^  s    zFunction._getobjc             C   s   | S )zA(compatonly) for code expecting pytest-2.2 style request objects.rR   )r   rR   rR   rS   _pyfuncitemb  s    zFunction._pyfuncitemc             C   s   | j j| d dS )z%Execute the underlying test function.)rk   N)r   rw   )r   rR   rR   rS   runtestg  s    zFunction.runtestc             C   s.   t | jtr | j  |  | _| j  d S )N)r   rz   r   rR  r   rr   r  Z_fillfixtures)r   rR   rR   rS   r+  k  s    

zFunction.setup)excinforA   c             C   s   t | dr| jddstjjt| j}|j	|j
 }}|j}|j||d}||kr||j|d}||kr||t}|s||}| |_| jdddkrt|jdkrx |jd	d
 D ]}|d qW d S )Nr   Z	fulltraceF)ry   firstlineno)ry   tbstyleautor  r   r   r  )ru   rU   r  r  _codeZCodefrom_functionr   rr   ry   r  r  Zcutr!  r   r  Zset_repr_style)r   r  codery   r  r  Z
ntracebackentryrR   rR   rS   _prunetracebackq  s     

zFunction._prunetracebackc             C   s(   | j dd}|dkrd}| j||dS )Nr  r  long)r  )rU   r  Z_repr_failure_py)r   r  r  rR   rR   rS   repr_failure  s    zFunction.repr_failure)r   r   r   r&  r   r$   r   r   r)   rV  r/   r.   r(  rQ  r   r  r   r  r   r  r  r+  r   BaseExceptionr  r   r   r  r'  rR   rR   )r   rS   rj     s(   $3c               @   s"   e Zd ZdZddddZeZdS )r   z
    This class is a step gap solution until we evolve to have actual function definition nodes
    and manage to get rid of ``metafunc``.
    N)rA   c             C   s   t dd S )Nz8function definitions are not supposed to be run as tests)RuntimeError)r   rR   rR   rS   r    s    zFunctionDefinition.runtest)r   r   r   r&  r  r+  rR   rR   rR   rS   r     s   r   )NNNN)r  )r&  r  r   r   r  r   r   typesrf   collectionsr   r   	functoolsr   typingr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r  r   r   Z_pytest._coder   r   Z_pytest._code.coder   r   Z_pytest._ior   Z_pytest._io.safereprr   Z_pytest.compatr   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r  r)   r*   r+   Z_pytest.config.argparsingr,   Z_pytest.deprecatedr-   rw  r.   r  r/   Z_pytest.markr0   r1   Z_pytest.mark.structuresr2   r3   r4   r5   Z_pytest.outcomesr6   r7   Z_pytest.pathlibr8   r9   r:   r;   Z_pytest.warning_typesr<   r=   Ztyping_extensionsr>   r?   rT   r   rW   ra   rc   r   ri   r  rw   ry   r   r  r   rP   r~   r   r   r   r   	frozensetuniondir
ModuleTyper   r   Filerx   r   r  r  r   r   rE  rF  rV  rX   r  rx  bytesr  r  r  r  rH   r  rC   r  r  r  rj   r   rR   rR   rR   rS   <module>   s  .

"a ~n	a=  4%   @29 