
^Yc           @` s  d  d l  m Z m Z m Z d  d l Z d  d l m 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 m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z d  d l m Z d  d l m Z d   Z i  Z e d	 f   Z d
 d f e d <e d d f e d <e d d f e d <e d d d f e d <e  e  d  Z! d   Z" d   Z# d   Z$ d   Z% d   Z& d   Z' d   Z( d   Z) d   Z* d f  d     YZ+ d e f d     YZ, d e, f d      YZ- d! e. f d"     YZ/ d# j0   Z1 e1 j2 d  Z3 d$   Z4 e  d%  Z5 d& e6 f d'     YZ7 d( e f d)     YZ8 d*   Z9 d+   Z: d, f  d-     YZ; d.   Z< d/ f  d0     YZ= d e  e> e  e  d1  Z? d e  e> e  e  d2  Z@ e?   ZA e? d3 d	  d4    ZB d5 f  d6     YZC d S(7   i    (   t   absolute_importt   divisiont   print_functionN(   t   FormattedExcinfo(   t   TerminalRepr(   t   NOTSETt	   exc_cleart   _format_argst   getfslinenot   get_real_funct   is_generatort   isclasst	   getimfunct   getlocationt   getfuncargnamest   safe_getattr(   t   fail(   t   FuncargnamesCompatAttrc         C` sS   d d  l  } t j i | j j d 6| j j d 6| j j d 6 t |   |  _	 d  S(   Ni    t   classt   modulet   function(
   t   _pytest.pythont   scopename2classt   updatet   pythont   Classt   Modulet   maint   Itemt   FixtureManagert   _fixturemanager(   t   sessiont   _pytest(    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyt   pytest_sessionstart   s    	R   t   fspathR   t   clsR   t   instanceR   t   keywordsc         ` s     f d   } | S(   Nc         ` s7    p   j      f d   } t | d  d    j  S(   Nc         ` s=     j  t |  j k r    |   St d  |  j f   d  S(   Ns%   %s not available in %s-scoped context(   t   __name__t   scope2propst   scopet   AttributeError(   t   self(   t   funct	   scopename(    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyt   provide-   s    
(   R&   t   propertyt   Nonet   __doc__(   R+   R-   (   t   name(   R+   R,   s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyt   decoratescope*   s    (    (   R1   t   docR2   (    (   R1   s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyt   scopeproperty)   s    
c         C` sJ   t  j |  } | d  k r= | d k r. |  j St d   n  |  j |  S(   NR   s   unknown scope(   R   t   getR/   R   t
   ValueErrort	   getparent(   t   nodeR(   R#   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyt   get_scope_node7   s    c      
   C` s  | j  d j s d  Si  } i  } x | j  D] } x | j j   D] \ } } | | j k sa t  | | j | <| j | g   } t |  | j | <| j |  | | k r@ | j	 j
 | t  }	 t |	 | | <q@ q@ W| j j   q* W| j }
 x | j   D] \ } } | | } d  } | d k rst |  |  } | d  k rs| d k rat |  t j j  sgt  |  } qsn  | r| | j k r| j | g |
 | <q t | d | t | | | t t  } | g |
 | <| d  k	 r | | j | <q q Wd  S(   Ni    R   R   t    (   t   _callst   funcargst   itemst   paramst   AssertionErrort
   setdefaultt   lent   indicest   appendt   _arg2scopenumR5   t   scopenum_functiont   scopest   cleart   _arg2fixturedefsR/   R9   t
   isinstanceR    R   R   t   _name2pseudofixturedeft
   FixtureDeft   get_direct_param_fixture_funct   False(   t	   collectort   metafunct   fixturemanagert
   arg2paramst	   arg2scopet   callspect   argnamet   argvaluet   arg2params_listt   scopenumt   arg2fixturedefst	   valuelistR(   R8   t
   fixturedef(    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyt   add_funcarg_pseudo_fixture_def@   sD    		
'c         C` s-   y t  |  d d  SWn t k
 r( d SXd S(   sK    return fixturemarker or None if it doesn't exist or raised
    exceptions.t   _pytestfixturefunctionN(   t   getattrR/   t	   Exception(   t   obj(    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyt   getfixturemarkerv   s    c         c` s   | t  k  s t  y |  j } Wn t k
 r2 n Xx | j j   D] \ } } | j | | k rh qC n  | d k r | | f } nH | d k r | | |  j f } n' | d k r | | |  j |  j f } n  | VqC Wd S(   sY    return list of keys for all parametrized arguments which match
    the specified scope. i    i   i   N(	   RE   R?   RS   R)   RB   R=   RD   R"   R#   (   t   itemRW   t   csRT   t   param_indext   key(    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyt   get_parametrized_fixture_keys   s    c         C` s}   i  } x^ t  d t  D]M } i  | | <} x6 |  D]. } t t | |   } | r1 | | | <q1 q1 Wq Wt |  t   | d  S(   Ni    (   t   rangeRE   t   setRe   t   reorder_items_atscope(   R=   t   argkeys_cacheRW   t   dRa   t   keys(    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyt   reorder_items   s    c   	      C` s   | t  k s t |   d k  r" |  Sg  } x t |  | | |  \ } } } } t | | | | d  } | d  k r | d  k s t  | | S| j |  | | }  | } q+ d  S(   Ni   i   (   RE   RA   t   slice_itemsRh   R/   R?   t   extend(	   R=   t   ignoreRi   RW   t
   items_donet   items_beforet
   items_samet   items_othert	   newignore(    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyRh      s    "
c         C` s  | rt  |   } x t |  D] \ } } | j |  } | d  k	 r | j |  } | r| j   } |  |  } | g }	 g  }
 xX | D]P } | j |  } | r | | k r | | k r |	 j |  q |
 j |  q W| j   } | j |  | |	 |
 | f Sq q Wn  |  d  d  d  f S(   N(	   t   itert	   enumerateR5   R/   t
   differencet   popRC   t   copyt   add(   R=   Ro   t   scoped_argkeys_cachet   itt   iRa   t   argkeyst   slicing_argkeyRq   Rr   Rs   Rt   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyRm      s*    
	c         C` s   y |  j  } Wn t k
 r |  j j } | j |  j |  j d  } | |  _ t	 |   } |  _  | j
   i  } x" | j D] } |  j | | | <qz W| |  _ n X| j
   d S(   s,    fill missing funcargs for a test function. N(   t   _requestR)   R   R   t   getfixtureinfot   parentR_   R/   t   _fixtureinfot   FixtureRequestt   _fillfixturest   argnamesR<   (   R   t   requestt   fmt   fit   newfuncargsR1   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyt   fillfixtures   s    	
c         C` s   |  j  S(   N(   t   param(   R   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyRL      s    t   FuncFixtureInfoc           B` s   e  Z d    Z RS(   c         C` s   | |  _  | |  _ | |  _ d  S(   N(   R   t   names_closuret   name2fixturedefs(   R*   R   R   R   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyt   __init__   s    		(   R&   t
   __module__R   (    (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyR      s   R   c           B` sU  e  Z d  Z d   Z e d    Z e d    Z d   Z e d    Z e	   d    Z
 e	 d  d    Z e d	    Z e	   d
    Z e	   d    Z e d    Z e d    Z d   Z d   Z d   Z d   Z d   Z d d d d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z  RS(   s    A request for a fixture from a test or fixture function.

    A request object gives access to the requesting test context
    and has an optional ``param`` attribute in case
    the fixture is parametrized indirectly.
    c         C` sd   | |  _  d  |  _ d |  _ i  |  _ i  |  _ | j } | j j   |  _	 i  |  _
 | j j |  _ d  S(   NR   (   t   _pyfuncitemR/   t   fixturenameR(   t   _fixture_valuest   _fixture_defsR   R   Ry   RH   t
   _arg2indexR   R   (   R*   t
   pyfuncitemt   fixtureinfo(    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyR     s    							c         C` s   t  |  j j j  S(   N(   t   listR   R   R   (   R*   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyt   fixturenames  s    c         C` s   |  j  |  j  S(   s>    underlying collection node (depends on current request scope)(   t   _getscopeitemR(   (   R*   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyR8     s    c         C` s   |  j  j | d   } | d  k rU |  j j j } |  j j | |  } | |  j  | <n  |  j j | d  d } | d  k s | t	 |  k r t
 | |    n  | |  j | <| | S(   Ni    i   (   RH   R5   R/   R   R   t   nodeidR   t   getfixturedefsR   RA   t   FixtureLookupError(   R*   RT   t   fixturedefst   parentidt   index(    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyt   _getnextfixturedef  s    c         C` s
   |  j  j S(   s8    the pytest config object associated with this request. (   R   t   config(   R*   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyR   +  s    c         C` s
   |  j  j S(   s?    test function object if the request has a per-function scope. (   R   R_   (   R*   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyR   1  s    R   c         C` s)   |  j  j t j j  } | r% | j Sd S(   s<    class (can be None) where the test function was collected. N(   R   R7   R    R   R   R_   (   R*   t   clscol(    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyR#   6  s    c         C` sT   y |  j  j SWn? t k
 rO t |  d d  } | d k	 rP t j j |  Sn Xd S(   s>    instance (can be None) on which test function was collected. R   N(   R   t	   _testcaseR)   R]   R/   t   pyt   builtint
   _getimself(   R*   R   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyR$   =  s    c         C` s   |  j  j t j j  j S(   s=    python module object where the test function was collected. (   R   R7   R    R   R   R_   (   R*   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyR   H  s    c         C` s
   |  j  j S(   sD    the file system path of the test module which collected this test. (   R   R"   (   R*   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyR"   M  s    c         C` s
   |  j  j S(   s6    keywords/markers dictionary for the underlying node. (   R8   R%   (   R*   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyR%   R  s    c         C` s
   |  j  j S(   s    pytest session object. (   R   R   (   R*   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyR   W  s    c         C` s   |  j  | d |  j d S(   s    add finalizer/teardown function to be called after the
        last test within the requesting test context finished
        execution. R(   N(   t   _addfinalizerR(   (   R*   t	   finalizer(    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyt   addfinalizer\  s    c         C` s2   |  j  |  } |  j j j j d | d |  d  S(   NR   t   colitem(   R   R   R   t   _setupstateR   (   R*   R   R(   R   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyR   c  s    c         C` s;   y | |  j  j | j <Wn t k
 r6 t |   n Xd S(   s.   Apply a marker to a single test function invocation.
        This method is useful if you don't want to have a keyword/marker
        on all function invocations.

        :arg marker: a :py:class:`_pytest.mark.MarkDecorator` object
            created by a call to ``pytest.mark.NAME(...)``.
        N(   R8   R%   t   marknameR)   R6   (   R*   t   marker(    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyt   applymarkerh  s    c         C` s   |  j  j d |  |   d S(   s4    raise a FixtureLookupError with the given message. N(   R   R   R/   (   R*   t   msg(    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyt
   raiseerroru  s    c         C` s[   |  j  } t | d |  j  } x6 | D]. } | | j k r% |  j |  | j | <q% q% Wd  S(   NR   (   R   R]   R   R<   t   getfixturevalue(   R*   Ra   R   RT   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyR   y  s
    	R   c         ` s   t  |  j d  s! i  |  j _ n  |  j |  j |  | f  |  j j   y     Wnw t k
 r |  j |  j |  j |  |        < d k	 r      f d   } |  j	 | d | q n X S(   sD   (deprecated) Return a testing resource managed by ``setup`` &
        ``teardown`` calls.  ``scope`` and ``extrakey`` determine when the
        ``teardown`` function will be called so that subsequent calls to
        ``setup`` would recreate the resource.  With pytest-2.3 you often
        do not need ``cached_setup()`` as you can directly declare a scope
        on a fixture function and register a finalizer through
        ``request.addfinalizer()``.

        :arg teardown: function receiving a previously setup resource.
        :arg setup: a no-argument function creating a resource.
        :arg scope: a string value out of ``function``, ``class``, ``module``
            or ``session`` indicating the caching lifecycle of the resource.
        :arg extrakey: added to internal caching key of (funcargname, scope).
        t   _setupcachec           ` s      =   d  S(   N(    (    (   t   cachet   cachekeyt   teardownt   val(    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyR     s    R(   N(
   t   hasattrR   R   R   R   t   KeyErrort   _check_scopeR(   R/   R   (   R*   t   setupR   R(   t   extrakeyR   (    (   R   R   R   R   s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyt   cached_setup  s    	
c         C` s   |  j  |  j d S(   s;   Dynamically run a named fixture function.

        Declaring fixtures via function argument is recommended where possible.
        But if you can only decide whether to use another fixture at test
        setup time, you may use this function to retrieve it inside a fixture
        or test function body.
        i    (   t   _get_active_fixturedeft   cached_result(   R*   RT   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyR     s    c         C` s0   d d l  m } t j | j t  |  j |  S(   s"    Deprecated, use getfixturevalue. i    (   t
   deprecated(   R    R   t   warningst   warnt   GETFUNCARGVALUEt   DeprecationWarningR   (   R*   RT   R   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyt   getfuncargvalue  s
    c         ` s   y   j  | SWnd t k
 ru y   j |  } Wqv t k
 rq | d k rk d d   f d     Y} | S  qv Xn X  j |  } |   j | <|   j  | <| S(   NR   t   PseudoFixtureDefc           ` s    e  Z   d  g d f Z d Z RS(   i    R   N(   R&   R   R/   R   R(   (    (   R*   (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyR     s   (    (   R   R   R   R   t   _getfixturevalueR   (   R*   RT   RZ   R   t   result(    (   R*   s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyR     s    c         C` sX   |  } g  } xE t  | d d   } | d  k r; | j   | S| j |  | j } q d  S(   Nt   _fixturedef(   R]   R/   t   reverseRC   t   _parent_request(   R*   t   currentt   lRZ   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyt   _get_fixturestack  s    
c         C` s  | j  } |  j } | j } y | j j |  } Wn t t f k
 rt } d } | j d  k	 rZt
 j   d } t
 j | d  } | j }	 | j }
 t j j |	  }	 |	 j | j j  r |	 j | j j  }	 n  d j | j  t | j | j j  |	 |
  } t |  qZnG X| j j j | d  } | j j j |  } | d  k	 rZt | } n  t |  | | | |  } | j | |  j |  t   z | j  d |  } Wd  |  j! j" j# | j$ | j%  X| S(   Ni    i   s   The requested fixture has no parameter defined for the current test.

Requested fixture '{0}' defined in:
{1}

Requested here:
{2}:{3}R   (&   RT   R   R(   RS   t   getparamR)   R6   R   R>   R/   t   inspectt   stackt   getframeinfot   filenamet   linenoR   t   patht   localt   reltoR   t   rootdirt   formatR   R+   R   RB   R5   RD   RF   t
   SubRequestR   R   t   executeR   R   R   t   finishR8   (   R*   RZ   RT   t   funcitemR(   R   Rc   t   framet	   frameinfot   source_patht   source_linenoR   t   paramscopenumt
   subrequestR   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyR     sD    						c         C` s[   | d k r d  St  | |  rW |  j   } t d | | | d j |  f d t n  d  S(   NR   sr   ScopeMismatch: You tried to access the %r scoped fixture %r with a %r scoped request object, involved factories
%ss   
t   pytrace(   t   scopemismatcht   _factorytracebackR   t   joinRM   (   R*   RT   t   invoking_scopet   requested_scopet   lines(    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyR   	  s    c         C` s   g  } xs |  j    D]e } | j } t |  \ } } |  j j j j |  } t |  } | j d | | | j	 | f  q W| S(   Ns   %s:%d:  def %s%s(
   R   R+   R   R   R   R"   t   bestrelpathR   RC   R&   (   R*   R   RZ   t   factoryt   fsR   t   pt   args(    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyR     s    		c         C` sY   | d k r |  j  St |  j  |  } | d  k rI | d k rI |  j  } n  | sU t  | S(   NR   R   (   R   R9   R/   R?   (   R*   R(   R8   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyR      s    c         C` s   d |  j  S(   Ns   <FixtureRequest for %r>(   R8   (   R*   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyt   __repr__+  s    N(!   R&   R   R0   R   R.   R   R8   R   R   R4   R   R#   R$   R   R"   R%   R   R   R   R   R   R   R/   R   R   R   R   R   R   R   R   R   R   (    (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyR      s8   							 	
				8			R   c           B` s    e  Z d  Z d   Z d   Z RS(   sP    a sub request for handling getting a fixture from a
    test function/fixture. c         C` s   | |  _  | j |  _ | t k	 r- | |  _ n  | |  _ | |  _ | |  _ | j |  _ | j	 |  _	 | j
 |  _
 | j |  _ | j |  _ | j |  _ | j |  _ d  S(   N(   R   RT   R   R   R   Rc   R(   R   R   R   R   R   RH   R   R   (   R*   R   R(   R   Rc   RZ   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyR   2  s    				c         C` s   d |  j  |  j f S(   Ns   <SubRequest %r for %r>(   R   R   (   R*   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyR   B  s    (   R&   R   R0   R   R   (    (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyR   /  s   	t   ScopeMismatchErrorc           B` s   e  Z d  Z RS(   s    A fixture function tries to use a different fixture function which
    which has a lower scope (e.g. a Session one calls a function one)
    (   R&   R   R0   (    (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyR   F  s   s   session module class functionc         C` s   t  j |  t  j |   k S(   N(   RF   R   (   t   currentscopet   newscope(    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyR   P  s    c         C` sY   y t  j |   SWnA t k
 rT t d j | | rB d j |  n d |     n Xd S(   s[   Look up the index of ``scope`` and raise a descriptive value error
    if not defined.
    s+   {0} {1}has an unsupported scope value '{2}'s	   from {0} R:   N(   RF   R   R6   R   (   R(   t   descrt   where(    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyt   scope2indexT  s    R   c           B` s#   e  Z d  Z d d  Z d   Z RS(   s<    could not return a requested Fixture (missing or invalid). c         C` s.   | |  _  | |  _ | j   |  _ | |  _ d  S(   N(   RT   R   R   t   fixturestackR   (   R*   RT   R   R   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyR   d  s    		c         C` s$  g  } | j  } |  j j j g } | j t d   |  j   |  j } | d  k	 r_ | d  } n  x | D] } t	 |  \ } } y t
 j t |   \ } }	 Wn8 t t t f k
 r d }
 | |
 | | d f  qf X| d | | d f  xM t |  D]? \ } } | j   } | d |  | j   j d  r Pq q Wqf W| d  k r|  j j } g  } |  j j j j } xW | j j   D]F \ } } t | j | |   } | r| | k r| j  |  qqWd |  j f } | d	 d
 j t |   f 7} | d 7} n  t | | | | |  j  S(   Nc         S` s   |  j  S(   N(   R+   (   t   x(    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyt   <lambda>n  s    is+   file %s, line %s: source code not availablei   s   file %s, line %ss     t   defs   fixture %r not founds   
 available fixtures: %ss   , s6   
 use 'pytest --fixtures [testpath]' for help on them.(   RC   R   R   R_   Rn   t   mapR   R   R/   R   R   t   getsourcelinesR	   t   IOErrort
   IndexErrort	   TypeErrorRv   t   rstript   lstript
   startswithR   R   R   RH   R=   R   t   _matchfactoriesRT   R   t   sortedt   FixtureLookupErrorRepr(   R*   t   tblinest   addlineR   R   R   R"   R   R   t   _t	   error_msgR}   t   lineR   t	   availableR   R1   R   t   faclist(    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyt
   formatreprj  s@    		 N(   R&   R   R0   R/   R   R  (    (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyR   b  s   R  c           B` s   e  Z d    Z d   Z RS(   c         C` s1   | |  _  | |  _ | |  _ | |  _ | |  _ d  S(   N(   R  t   errorstringR   t   firstlinenoRT   (   R*   R   R  R  R  RT   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyR     s
    				c         C` s   x$ |  j  D] } | j | j    q
 W|  j j d  } | r | j d j t j | d j    d t	 x= | d D]. } | j d j t j
 | j    d t	 qv Wn  | j   | j d |  j |  j d f  d  S(   Ns   
s   {0}       {1}i    t   redi   s   %s:%d(   R  R  R  R  t   splitR   R   t   fail_markert   stript   Truet   flow_markerR   R  (   R*   t   twt   tblineR   R  (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyt
   toterminal  s    
(   R&   R   R   R  (    (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyR    s   	c         C` sh   t  |   \ } } d | | d f } t j j |   } t | d t | j    d | d t d  S(   Ns   %s:%si   s   :

s   
R   (   R   R    t   _codet   SourceR   t   strt   indentRM   (   t   fixturefuncR   R   R   t   locationt   source(    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyt   fail_fixturefunc  s
    %c         ` s\   t     } | rL   |    t   }    f d   } | j |  n   |   } | S(   Nc           ` s3   y t    Wn t k
 r! n Xt   d  d  S(   Ns0   yield_fixture function has more than one 'yield'(   t   nextt   StopIterationR!  (    (   R  R|   (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyR     s    (   R
   R"  R   (   R  R   t   kwargst   yieldctxt   resR   (    (   R  R|   s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyt   call_fixture_func  s    	RK   c           B` sA   e  Z d  Z e d d  Z d   Z d   Z d   Z d   Z	 RS(   s'    A container for a factory definition. c	   
      C` s   | |  _  | p d |  _ | d  k	 |  _ | |  _ | |  _ | |  _ t | pN d d d j | j	  d | |  _
 | |  _ | r d p d  }	 t | d |	 |  _ | |  _ | |  _ g  |  _ d  S(   NR:   R   R   s   fixture {0}R   i   t
   startindex(   R   t   baseidR/   t   has_locationR+   RT   R(   R   R   R&   RW   R>   R   R   t   unittestt   idst
   _finalizer(
   R*   RP   R)  RT   R+   R(   R>   R+  R,  R(  (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyR     s     							c         C` s   |  j  j |  d  S(   N(   R-  RC   (   R*   R   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyR     s    c         C` s   g  } zq xD |  j  rO y |  j  j   } |   Wq | j t j    q Xq W| rv | d } ~ t j j |   n  Wd  |  j j	 j
 } | j d |   t |  d  r |  ` n  Xd  S(   Ni    RZ   R   (   R-  Rx   RC   t   syst   exc_infoR   R   t   _reraiseR   R   t   ihookt   pytest_fixture_post_finalizerR   R   (   R*   t
   exceptionsR+   t   eR1  (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyR     s     
c   
      C` s   x? |  j  D]4 } | j |  } | d k r
 | j |  j  q
 q
 W| j } t |  d d   } | d  k	 r | \ } } } | | k r | d  k	 r t j j	 |   q | Sn  |  j   t
 |  d  s t  n  |  j j j }	 |	 j d |  d |  S(   NR   R   RZ   (   R   R   R   R   Rc   R]   R/   R   R   R0  R   R?   R   R   R1  t   pytest_fixture_setup(
   R*   R   RT   RZ   t   my_cache_keyR   R   t	   cache_keyt   errR1  (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyR     s     	
c         C` s   d |  j  |  j |  j f S(   Ns(   <FixtureDef name=%r scope=%r baseid=%r >(   RT   R(   R)  (   R*   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyR     s    N(
   R&   R   R0   RM   R/   R   R   R   R   R   (    (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyRK     s   			c   
      C` sC  i  } xU |  j  D]J } | j |  } | j \ } } } | j | | j | j  | | | <q W|  j } |  j r | j d k	 r |  j j	 | j  } q nE | j d k	 r t
 |  j  } | |  j k r | j	 | j  } q n  | j }	 y t | | |  } Wn, t k
 r,d |	 t j   f |  _   n X| |	 d f |  _ | S(   s    Execution of fixture setup. N(   R   R   R   R   R(   R+   R+  R$   R/   t   __get__R   Rc   R'  R^   R.  R/  (
   RZ   R   R$  RT   t   fixdefR   t   arg_cache_keyt   excR  R6  (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyR5    s,    			t   FixtureFunctionMarkerc           B` s#   e  Z e d d d   Z d   Z RS(   c         C` s1   | |  _  | |  _ | |  _ | |  _ | |  _ d  S(   N(   R(   R>   t   autouseR,  R1   (   R*   R(   R>   R>  R,  R1   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyR   3  s
    				c         C` s(   t  |  r t d   n  |  | _ | S(   Ns3   class fixtures not supported (may be in the future)(   R   R6   R\   (   R*   R   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyt   __call__:  s
    	N(   R&   R   RM   R/   R   R?  (    (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyR=  2  s   c         C` s   t  |   r@ | d k r@ | t k r@ t d | | d | |   S| d k	 rq t | t t f  rq t |  } n  t |  | | d | d | S(   s   (return a) decorator to mark a fixture factory function.

    This decorator can be used (with or without parameters) to define a
    fixture function.  The name of the fixture function can later be
    referenced to cause its invocation ahead of running tests: test
    modules or classes can use the pytest.mark.usefixtures(fixturename)
    marker.  Test functions can directly use fixture names as input
    arguments in which case the fixture instance returned from the fixture
    function will be injected.

    :arg scope: the scope for which this fixture is shared, one of
                "function" (default), "class", "module" or "session".

    :arg params: an optional list of parameters which will cause multiple
                invocations of the fixture function and all of the tests
                using it.

    :arg autouse: if True, the fixture func is activated for all tests that
                can see it.  If False (the default) then an explicit
                reference is needed to activate the fixture.

    :arg ids: list of string ids each corresponding to the params
                so that they are part of the test id. If no ids are provided
                they will be generated automatically from the params.

    :arg name: the name of the fixture. This defaults to the name of the
                decorated function. If a fixture is used in the same module in
                which it is defined, the function name of the fixture will be
                shadowed by the function arg that requests the fixture; one way
                to resolve this is to name the decorated function
                ``fixture_<fixturename>`` and then use
                ``@pytest.fixture(name='<fixturename>')``.

    Fixtures can optionally provide their values to test functions using a ``yield`` statement,
    instead of ``return``. In this case, the code block after the ``yield`` statement is executed
    as teardown code regardless of the test outcome. A fixture function must yield exactly once.
    R   R1   R,  N(   t   callableR/   RM   R=  RI   R   t   tuple(   R(   R>   R>  R,  R1   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyt   fixtureC  s    &$"c         C` sa   t  |   rA | d k rA | rA t d | | d | d | |   St |  | | d | d | Sd S(   s    (return a) decorator to mark a yield-fixture factory function.

    .. deprecated:: 3.0
        Use :py:func:`pytest.fixture` directly instead.
    R   R,  R1   N(   R@  R/   R=  (   R(   R>   R>  R,  R1   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyt   yield_fixturer  s    R(   c         C` s   |  j  S(   s;    the pytest config object with access to command line opts.(   R   (   R   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyt   pytestconfig  s    R   c           B` s   e  Z d  Z d Z e Z e Z d   Z e d  Z d   Z	 d   Z
 d   Z d   Z d   Z e e d	  Z d
   Z d   Z RS(   s  
    pytest fixtures definitions and information is stored and managed
    from this class.

    During collection fm.parsefactories() is called multiple times to parse
    fixture function definitions into FixtureDef objects and internal
    data structures.

    During collection of test functions, metafunc-mechanics instantiate
    a FuncFixtureInfo object which is cached per node/func-name.
    This FuncFixtureInfo object is later retrieved by Function nodes
    which themselves offer a fixturenames attribute.

    The FuncFixtureInfo object holds information about fixtures and FixtureDefs
    relevant for a particular function.  An initial list of fixtures is
    assembled like this:

    - ini-defined usefixtures
    - autouse-marked fixtures along the collection chain up from the function
    - usefixtures markers at module/class/function level
    - test function funcargs

    Subsequently the funcfixtureinfo.fixturenames attribute is computed
    as the closure of the fixtures needed to setup the initial fixtures,
    i. e. fixtures needed by fixture functions themselves are appended
    to the fixturenames list.

    Upon the test-setup phases all fixturenames are instantiated, retrieved
    by a lookup of their FuncFixtureInfo.
    t   pytest_funcarg__c         C` sk   | |  _  | j |  _ i  |  _ t   |  _ i  |  _ d |  j j d  f g |  _ | j j j	 |  d  d  S(   NR:   t   usefixturest
   funcmanage(
   R   R   RH   Rg   t   _holderobjseent   _arg2finisht   getinit   _nodeid_and_autousenamest   pluginmanagert   register(   R*   R   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyR     s    			c         C` s   | rC t  | d  rC | d  k	 r+ d } n d  } t | |  } n d } t | d d   } | } | d  k	 r} | j | } n  | j j }	 |	 j | |  \ }
 } t | |
 |  S(   Nt
   nofuncargsi   RF  (    (	   R   R/   R   R]   R   R   R   t   getfixtureclosureR   (   R*   R8   R+   R#   R<   R(  R   RF  t   initialnamesR   R   RX   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyR     s    		c         C` s   d  } y t j j | j  } Wn t k
 r2 nX X| j j d  r | j   j	 |  j
 j  } | j d k r | j | j d  } q n  |  j | |  d  S(   Ns   conftest.pyt   /(   R/   R   R   R   t   __file__R)   t   basenameR  t   dirpathR   R   R   t   sept   replacet   parsefactories(   R*   t   pluginR   R   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyt   pytest_plugin_registered  s    c         ` s   g  } xt   j  D]i \ } } | j |  r | ri t |  } | | | d !} | ri | d k ri q qi n  | j |  q q W| j d   f d    | S(   s-    return a tuple of fixture names to be used. i   s   :/Rd   c         ` s     j  |  d j S(   Ni(   RH   RW   (   R   (   R*   (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyR     s    (   RK  R  RA   Rn   t   sort(   R*   R   t   autousenamesR)  t	   basenamesR}   t   nextchar(    (   R*   s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyt   _getautousenames  s    		c   	      ` s   | j  } |  j |      f d   } | |  i  } d } x{ | t    k r t    } xV   D]N } | | k r} qe n  |  j | |  } | re | | | <| | d j  qe qe Wq@ W  | f S(   Nc         ` s1   x* |  D]" } |   k r   j  |  q q Wd  S(   N(   RC   (   t	   otherlistt   arg(   t   fixturenames_closure(    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyt   merge  s    i(   R   R^  RA   R   R   (	   R*   R   t
   parentnodeR   Rb  RX   t   lastlenRT   R   (    (   Ra  s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyRO    s     	

c      
   C` s  x| j  D]} | j j |  } | r
 | d } | j d  k	 rt t | j d d   d d  g g  } | d } t | t t	 f  s g  | j
 d  D] } | j   r | j   ^ q } n  | | k r| | k r| j | | j d t d | j d | j qqq
 q
 q
 Wd  S(	   Nit   parametrizeR   i    t   ,t   indirectR(   R,  (   R   RH   R5   R>   R/   R]   R   RI   RA  R   R  R  Re  R  R(   R,  (   R*   RO   RT   R  RZ   t   func_paramsR   R   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyt   pytest_generate_tests  s    
'
7c         C` s   t  |  | (d  S(   N(   Rl   (   R*   R=   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyt   pytest_collection_modifyitems  s    c         C` s:  | t  k	 r | } n | j } | j } | |  j k r: d  S|  j j |  g  } xt |  D]} t | | d   } t |  } | d  k r| j	 |  j
  s q] n  t |  s q] n  t } d d l m }	 |  j j d |	 j j d |  d | | t |  j
  } nS t | t  s q] n> | j r5| j } n  d | }
 | j	 |  j
  s^t |
   t |  | | | | j | j d | d | j } |  j j | g   } | j r| j |  n8 t g  | D] } | j s| ^ q } | j  | |  | j! r] | j |  q] q] W| r6|  j" j | p)d	 | f  n  d  S(
   Ni    (   R   t   C1R1   R   sX   fixtures cannot have "pytest_funcarg__" prefix and be decorated with @pytest.fixture:
%sR+  R,  R:   (#   R   R_   R   RH  Rz   t   dirR   R/   R`   R  t
   _argprefixR@  t   defaultfuncargprefixmarkerR    R   R   R   t   FUNCARG_PREFIXR   RA   RI   R=  R1   R?   RK   R(   R>   R,  RH   R@   R*  RC   t   insertR>  RK  (   R*   t   node_or_objR   R+  t	   holderobjR[  R1   R_   R   R   R   t   fixture_defR  t   fR}   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyRW    sN    			(		(	c         C` s@   y |  j  | } Wn t k
 r% d SXt |  j | |   Sd S(   s   
        Gets a list of fixtures which are applicable to the given node id.

        :param str argname: name of the fixture to search for
        :param str nodeid: full node id of the requesting test.
        :return: list[FixtureDef]
        N(   RH   R   R/   RA  R  (   R*   RT   R   R   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyR   V  s
    c         c` s/   x( | D]  } | j  | j  r | Vq q Wd  S(   N(   R  R)  (   R*   R   R   RZ   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyR  e  s    (   R&   R   R0   Rm  R   R  R   R  R   RY  R^  RO  Ri  Rj  R   RM   RW  R   R  (    (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyR     s   	
					9	(D   t
   __future__R    R   R   R.  t   py._code.codeR   R   R   R   R    t   _pytest._code.codeR   t   _pytest.compatR   R   R   R   R	   R
   R   R   R   R   R   t   _pytest.runnerR   R   R!   R   t   dictR'   R/   R4   R9   R[   R`   Re   Rl   Rh   Rm   R   RL   R   R   R   R^   R   R  RF   R   RE   R   R   t   LookupErrorR   R  R!  R'  RK   R5  R=  RM   RB  RC  Rn  RD  R   (    (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/fixtures.pyt   <module>   s`   L	
			6			
				 5	0		L	 /	