o
    :h                    @  s  d 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ZddlZddl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ZddlZddlZddlZdd
lm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&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/m0Z0 ddl/m1Z1 ddl2m3Z3 ddl4m5Z5 ddl6Z4ddl6m7Z7 ddl6m8Z8 dd l9m:Z: dd!l;m<Z< dd"l=m>Z> dd#l=m?Z? ddl@Z4ddlAZ4dd$lBmCZC dd%lBmDZD dd&lEmFZF dd'lEmGZG dd(lEmHZH dd)lEmIZI dd*lEmJZJ dd+lEmKZK dd,lLmMZM dd-lNmOZO dd.lNmPZP e%ridd/lQmRZR dd0lSmTZT dd1lUmVZV eWZX	 e(d2ZYe*d2ZZe"G d3d4 d4ej[Z\G d5d6 d6e]Z^dd;d<Z_		dddBdCZ`ddEdFZaG dGdH dHZbddLdMZcddNdOZddPZeg eedQdRdSdTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcdddedfdgdhdiR Zfh efdjdkZg		dddndoZhddqdrZi		dddsdtZjddvdwZkdd~dZle"G ddp dpe,ZmdddZnG dd dZoeo ZpdddZqe"G ddm dmZrdddZs	ddddZtdddZuedddddZvdddZwdddZxdS )z:Command line options, ini-file and conftest.py processing.    )annotationsN)Callable)	Generator)Iterable)Iterator)Sequence)	lru_cache)dedent)FunctionType)Any)cast)Final)final)IO)TextIO)TYPE_CHECKING)HookimplMarker)HookimplOpts)HookspecMarker)HookspecOpts)PluginManager   )PathAwareHookProxy)	PrintHelp)
UsageError)determine_setup)__version__)ExceptionInfo)filter_traceback)TracebackStyle)TerminalWriter)ArgumentParser)fail)Skipped)absolutepath)bestrelpath)import_path)
ImportMode)resolve_package_path)safe_exists)Stash)PytestConfigWarning)warn_explicit_for)AssertionRewritingHook)Cache)TerminalReporterpytestc                   @  s(   e Zd ZdZdZdZdZdZdZdZ	dS )	ExitCodezEncodes the valid exit codes by pytest.

    Currently users and plugins may supply other exit codes as well.

    .. versionadded:: 5.0
    r   r               N)
__name__
__module____qualname____doc__OKTESTS_FAILEDINTERRUPTEDINTERNAL_ERRORUSAGE_ERRORNO_TESTS_COLLECTED rB   rB   W/var/www/html/flask_server/venv/lib/python3.10/site-packages/_pytest/config/__init__.pyr3   [   s    r3   c                   @  s    e Zd ZdddZdd
dZdS )ConftestImportFailurepathpathlib.Pathcause	ExceptionreturnNonec                C  s   || _ || _d S N)rE   rG   )selfrE   rG   rB   rB   rC   __init__s   s   
zConftestImportFailure.__init__strc                 C  s"   t | jj d| j d| j dS )N: z (from ))typerG   r8   rE   rL   rB   rB   rC   __str__|   s   "zConftestImportFailure.__str__N)rE   rF   rG   rH   rI   rJ   )rI   rN   )r8   r9   r:   rM   rS   rB   rB   rB   rC   rD   r   s    
	rD   entry_pytest._code.TracebackEntryrI   boolc                 C  s   t | odt| jtjvS )zFilter tracebacks entries which point to pytest internals or importlib.

    Make a special case for importlib because we use it to import test modules and conftest files
    in _pytest.pathlib.import_path.
    	importlib)r   rN   rE   splitossep)rT   rB   rB   rC   ,filter_traceback_for_conftest_import_failure   s   r[   args#list[str] | os.PathLike[str] | Noneplugins$Sequence[str | _PluggyPlugin] | Noneint | ExitCodec              
   C  s:  t jd}zztt jd< zt| |}W nh ty} } z\t|j}t	t
j}|jd|j ddd |jt|_|jrE|jdddn| }t|}| D ]}	|j|	 dd qQtjW  Y d	}~W W |d	u rst jdd	 S |t jd< S d	}~ww zH|jj|d
}
zt|
W W |  W W |d	u rt jdd	 S |t jd< S  ty   |
 Y W |  W W |d	u rt jdd	 S |t jd< S w |  w  ty	 } z1t	t
j}|jD ]}|jd| ddd qtjW  Y d	}~W |d	u rt jdd	 S |t jd< S d	}~ww |d	u rt jdd	 w |t jd< w )aL  Perform an in-process test run.

    :param args:
        List of command line arguments. If `None` or not given, defaults to reading
        arguments directly from the process command line (:data:`sys.argv`).
    :param plugins: List of plugin objects to be auto-registered during initialization.

    :returns: An exit code.
    PYTEST_VERSIONz$ImportError while loading conftest 'z'.T)redshortF)stylechainNconfigzERROR: 
)rY   environgetr   _prepareconfigrD   r   from_exceptionrG   r    sysstderrlinerE   	tracebackfilterr[   getreprexconlyrN   
splitlinesrstripr3   r@   pophookpytest_cmdline_main_ensure_unconfigure
ValueErrorr   r\   )r\   r^   old_pytest_versionrg   eexc_infotwexc_reprformatted_tbro   retmsgrB   rB   rC   main   sl   






r   intc                  C  sN   zt  } tj  | W S  ty&   ttjtj}t	|tj
  Y dS w )zoThe CLI entry point of pytest.

    This function is not meant for programmable use; use `main()` instead.
    r   )r   rm   stdoutflushBrokenPipeErrorrY   opendevnullO_WRONLYdup2fileno)coder   rB   rB   rC   console_main   s   
r   c                   @  s   e Zd ZeeZdS )cmdlineN)r8   r9   r:   staticmethodr   rB   rB   rB   rC   r          r   rE   rN   optnamec                 C  s"   t j| rt| d|  | S )ztArgparse type validator for filename arguments.

    :path: Path of filename.
    :optname: Name of the option.
    z must be a filename, given: rY   rE   isdirr   rE   r   rB   rB   rC   filename_arg      r   c                 C  s"   t j| st| d|  | S )zvArgparse type validator for directory arguments.

    :path: Path of directory.
    :optname: Name of the option.
    z must be a directory, given: r   r   rB   rB   rC   directory_arg   r   r   )markr   runnerfixtures
helpconfigpythonterminal	debuggingunittestcaptureskipping
legacypathtmpdirmonkeypatchrecwarnpastebin	assertionjunitxmldoctestcacheproviderfreeze_support	setuponly	setupplanstepwiseunraisableexceptionthreadexceptionwarningsloggingreportsfaulthandlerpytesterpytester_assertionslist[str] | NoneConfigc                 C  sV   t  }t|tj| p
d|tj dd}| d ur|j| dd tD ]}|| q!|S )NrB   r\   r^   dirinvocation_paramsTexclude_only)	PytestPluginManagerr   InvocationParamspathlibPathcwdconsider_preparsedefault_pluginsimport_plugin)r\   r^   pluginmanagerrg   specrB   rB   rC   
get_config  s   	r   r   c                   C  s   t  jS )zObtain a new instance of the
    :py:class:`pytest.PytestPluginManager`, with default plugins
    already loaded.

    This function can be used by integration with other tools, like hooking
    into pytest to run tests into an IDE.
    )r   r   rB   rB   rB   rC   get_plugin_manager4  s   r   c                 C  s   | d u rt jdd  } nt| tjrt| g} nt| ts*d}t|| t	| t
| |}|j}z"|rJ|D ]}t|trD|| q7|| q7|jj|| d}|W S  ty`   |   w )Nr   zG`args` parameter expected to be a list of strings, got: {!r} (type: {}))r   r\   )rm   argv
isinstancerY   PathLikefspathlist	TypeErrorformatrQ   r   r   rN   consider_pluginargregisterrw   pytest_cmdline_parseBaseExceptionry   )r\   r^   r   rg   r   pluginrB   rB   rC   rk   ?  s0   


rk   rF   c                 C  s   |   r| jS | S )z<Get the directory of a path - itself if already a directory.)is_fileparent)rE   rB   rB   rC   _get_directory_  s   r   methodr   	hook_type	opt_namestuple[str, ...]dict[str, bool]c           
      C  s   t r	t| s	J dd t| dg D }g }i }|D ]0}t| |t}|tur5|| d|  d||< q||v rF|| d d||< qd||< q|red|}tjj	j
|| j|d	}	ttt| |	 |S )
Nc                 S  s   h | ]}|j qS rB   name).0mrB   rB   rC   	<setcomp>o  s    z)_get_legacy_hook_marks.<locals>.<setcomp>
pytestmark=Tz=TrueF, )rQ   fullname	hook_opts)r   inspect	isroutinegetattrAttributeErrorappendjoin_pytest
deprecatedHOOK_LEGACY_MARKINGr   r:   r.   r   r
   )
r   r   r   known_marks	must_warnoptsopt_nameopt_attrr   messagerB   rB   rC   _get_legacy_hook_marksg  s.   



r   c                      s
  e Zd ZdZdZ fddZd[ fddZd\ fddZd]d^ fddZd_ddZd`ddZ	daddZ
dbd)d*Zdcd,d-Zddd0d1Zded2d3Zdfd5d6Zdgd8d9Zdhd<d=Zdid?d@ZdAdBdjdEdFZdkdHdIZdldLdMZdZdNdOZdmdPdQZdndTdUZdodpdXdYZ  ZS )qr   a;  A :py:class:`pluggy.PluginManager <pluggy.PluginManager>` with
    additional pytest-specific functionality:

    * Loading plugins from the command line, ``PYTEST_PLUGINS`` env variable and
      ``pytest_plugins`` global variables found in plugins being loaded.
    * ``conftest.py`` loading during start-up.
    rI   rJ   c                   s   ddl m} ddl m} t d t | _i | _d | _d| _	t
dt| _g | _| tj | |  tjdritj}t|dd	}ztt| |jd
|d}W n	 ty\   Y nw | jj|j |    | | _!d| _"d S )Nr   )DummyRewriteHook)RewriteHookr2   F   PYTEST_DEBUGencodingutf8r   )mode	bufferingr   )#_pytest.assertionr   r   superrM   set_conftest_plugins_dirpath2confmods_confcutdir_noconftestr   r   skipped_pluginsadd_hookspecsr   hookspecr   rY   ri   rj   rm   rn   r   r   dupr   r   rH   traceroot	setwriterwriteenable_tracingrewrite_hook_configured)rL   r   r   errr   	__class__rB   rC   rM     s8   


zPytestPluginManager.__init__r   _PluggyPluginr   rN   HookimplOpts | Nonec                   sb   | dsdS |dkrdS t ||}|dur|S t||}t|s&dS t|dd}tt|S ):meta private:pytest_Npytest_pluginsimpl)tryfirsttrylastoptionalhookhookwrapper)	
startswithr  parse_hookimpl_optsr   r   r   r   r   r   )rL   r   r   r   r   legacyr  rB   rC   r"    s   



z'PytestPluginManager.parse_hookimpl_optsHookspecOpts | Nonec                   sD   t  ||}|du r t||}|dr t|dd}tt|}|S )r  Nr  r   )firstresulthistoric)r  parse_hookspec_optsr   r!  r   r   r   )rL   module_or_classr   r   r   r#  r  rB   rC   r'    s   


z'PytestPluginManager.parse_hookspec_optsN
str | Nonec              	     sv   |t jjv rttd|dd d S t 	||}|d ur9| j
jjt||| dd t|tjr9| | |S )NzQ{} plugin has been merged into the core, please remove it from your requirements._-)r   plugin_namemanagerkwargs)r   r   DEPRECATED_EXTERNAL_PLUGINSr   warnr-   r   replacer  r   rw   pytest_plugin_registeredcall_historicdictr   types
ModuleTypeconsider_module)rL   r   r   r,  r  rB   rC   r     s,   

zPytestPluginManager.registerc                 C  s   |  |}|S rK   )
get_plugin)rL   r   r   rB   rB   rC   	getplugin  s   
zPytestPluginManager.getpluginrV   c                 C  s   t | |S )z:Return whether a plugin with the given name is registered.)rV   r9  )rL   r   rB   rB   rC   	hasplugin
     zPytestPluginManager.haspluginrg   r   c                 C  s"   | dd | dd d| _dS )r  markersztryfirst: mark a hook implementation function such that the plugin machinery will try to call it first/as early as possible. DEPRECATED, use @pytest.hookimpl(tryfirst=True) instead.ztrylast: mark a hook implementation function such that the plugin machinery will try to call it last/as late as possible. DEPRECATED, use @pytest.hookimpl(trylast=True) instead.TN)addinivalue_liner  )rL   rg   rB   rB   rC   pytest_configure  s   
z$PytestPluginManager.pytest_configurer\   Sequence[str | pathlib.Path]pyargs
noconftestrootpathrF   
confcutdirpathlib.Path | Noneinvocation_dir
importmodeImportMode | strconsider_namespace_packagesc                C  s   |rt || nd| _|| _|| _d}	|D ]*}
t|
}|d}|dkr*|d| }t || }t|r?| j||||d d}	q|	sM| j||||d dS dS )a`  Load initial conftest files given a preparsed "namespace".

        As conftest files may add their own command line options which have
        arguments ('--my-opt somepath') we might get some false positives.
        All builtin and 3rd party plugins will have been loaded, however, so
        common options will not confuse our logic here.
        NF::rI  T)r&   r  r  _using_pyargsrN   findr+   _try_load_conftest)rL   r\   rA  rB  rC  rD  rF  rG  rI  foundanchorinitial_pathrE   ianchorrB   rB   rC   _set_initial_conftests#  s8   

z*PytestPluginManager._set_initial_conftestsrE   c                 C  s   | j du rdS || j jvS )z:Whether to consider the given path to load conftests from.NT)r  parentsrL   rE   rB   rB   rC   _is_in_confcutdirV  s   

z%PytestPluginManager._is_in_confcutdirrS  str | ImportModec                C  sL   | j ||||d | r"|dD ]}| r!| j ||||d qd S d S )NrL  ztest*)_loadconftestmodulesis_dirglob)rL   rS  rG  rC  rI  xrB   rB   rC   rO  e  s$   z&PytestPluginManager._try_load_conftestc          
      C  s   | j rd S | |}|| jv rd S g }t|g|jR D ]}| |r9|d }| r9| j||||d}	||	 q|| j|< d S )Nzconftest.pyrL  )	r  r   r  reversedrU  rW  r   _importconftestr   )
rL   rE   rG  rC  rI  	directoryclistr   conftestpathmodrB   rB   rC   rY  ~  s&   



z(PytestPluginManager._loadconftestmodulesSequence[types.ModuleType]c                 C  s   |  |}| j|dS )NrB   )r   r  rj   )rL   rE   r_  rB   rB   rC   _getconftestmodules  s   
z'PytestPluginManager._getconftestmodulestuple[types.ModuleType, Any]c              	   C  sF   |  |}t|D ]}z
|t||fW   S  ty   Y q	w t|rK   )rd  r]  r   r   KeyError)rL   r   rE   modulesrb  rB   rB   rC   _rget_with_confmod  s   
z&PytestPluginManager._rget_with_confmodra  types.ModuleTypec             
   C  sB  t |}| |}|d urttj|S t|}|d u r,ztj|j= W n	 t	y+   Y nw z
t
||||d}W n tyP }	 z|	jd usEJ t||	d|	d }	~	ww | || | j| |j}
|
| jv r| j D ]%\}}|
|jv sw||
kr||v rtd|d| d|j d|| qj| d| | j||d |S )	N)r   r  rI  )rG   z#While trying to load conftest path z, found that the module z is already loaded with path zE. This is not supposed to happen. Please report this issue to pytest.zloading conftestmodule )registration_name)rN   r9  r   r6  r7  r*   rm   rg  stemrf  r(   rH   __traceback__rD   _check_non_top_pytest_pluginsr  addr   r  itemsrU  AssertionError__file__r   r  consider_conftest)rL   ra  rG  rC  rI  conftestpath_plugin_nameexistingpkgpathrb  r|   dirpathrE   modsrB   rB   rC   r^    sT   



z#PytestPluginManager._importconftestrb  c                 C  s@   t |dr| jr| jsd}t||| jdd d S d S d S d S )Nr  af  Defining 'pytest_plugins' in a non-top-level conftest is no longer supported:
It affects the entire test suite instead of just below the conftest as expected.
  {}
Please move it to a top level conftest file at the rootdir:
  {}
For more information, visit:
  https://docs.pytest.org/en/stable/deprecations.html#pytest-plugins-in-non-top-level-conftest-filesF)pytrace)hasattrr  rM  r$   r   r  )rL   rb  ra  r   rB   rB   rC   rm    s   	z1PytestPluginManager._check_non_top_pytest_pluginsFr   Sequence[str]r   c                C  s   d}t |}||k rU|| }|d7 }t|trO|dkr1z|| }W n
 ty+   Y dS w |d7 }n|dr=|dd }nq| }|rJ|dsJq| | ||k s
dS dS )r  r   r   z-pNr4   no:)lenr   rN   
IndexErrorr!  stripr   )rL   r\   r   rR  noptpargrB   rB   rC   r     s*   



z%PytestPluginManager.consider_preparseargc                 C  s   | dr:|dd }|tv rtd| d|dkr%| d | d | | | d	s8| d	|  dS dS |}| | | d	sM| d	|  | j|d
d dS )r  r{  r5   Nzplugin z cannot be disabledr   r   pytest_stepwiser  T)consider_entry_points)r!  essential_pluginsr   set_blockedunblockr   )rL   r  r   rB   rB   rC   r     s    






z&PytestPluginManager.consider_pluginargconftestmodulerj  c                 C  s   | j ||d dS )r  r   N)r   )rL   r  rj  rB   rB   rC   rr  .  s   z%PytestPluginManager.consider_conftestc                 C  s   |  tjd dS )r  PYTEST_PLUGINSN)_import_plugin_specsrY   ri   rj   rR   rB   rB   rC   consider_env4     z PytestPluginManager.consider_envc                 C  s   |  t|dg  dS )r  r  N)r  r   )rL   rb  rB   rB   rC   r8  8  r  z#PytestPluginManager.consider_moduler   -None | types.ModuleType | str | Sequence[str]c                 C  s    t |}|D ]}| | qd S rK   )_get_plugin_specs_as_listr   )rL   r   r^   import_specrB   rB   rC   r  <  s   z(PytestPluginManager._import_plugin_specsmodnamer  c              
   C  s  t |tsJ d|| |s| |durdS |tv r"d| n|}| j| |r7| jd|d}|r7dS zt| W n; t	y[ } zt	d| d|j
d  |j|d}~w tyx } z| j||jpjd	f W Y d}~dS d}~ww tj| }| || dS )
zImport a plugin with ``modname``.

        If ``consider_entry_points`` is True, entry point names are also
        considered to find a plugin.
        z"module name as text required, got Nz_pytest.pytest11r   zError importing plugin "z": r    )r   rN   
is_blockedr9  builtin_pluginsr  mark_rewriteload_setuptools_entrypoints
__import__ImportErrorr\   with_tracebackrl  r%   r	  r   r   rm   rg  r   )rL   r  r  
importspecloadedr|   rb  rB   rB   rC   r   C  s4   

$
z!PytestPluginManager.import_pluginrI   rJ   )r   r  r   rN   rI   r  )r   rN   rI   r$  rK   )r   r  r   r)  rI   r)  r   rN   )r   rN   rI   rV   )rg   r   rI   rJ   )r\   r@  rA  rV   rB  rV   rC  rF   rD  rE  rF  rF   rG  rH  rI  rV   rI   rJ   )rE   rF   rI   rV   )
rS  rF   rG  rX  rC  rF   rI  rV   rI   rJ   )
rE   rF   rG  rX  rC  rF   rI  rV   rI   rJ   )rE   rF   rI   rc  )r   rN   rE   rF   rI   re  )
ra  rF   rG  rX  rC  rF   rI  rV   rI   ri  )rb  ri  ra  rF   rI   rJ   )r\   rz  r   rV   rI   rJ   )r  rN   rI   rJ   )r  ri  rj  rN   rI   rJ   )rb  ri  rI   rJ   )r   r  rI   rJ   )F)r  rN   r  rV   rI   rJ   )r8   r9   r:   r;   rM   r"  r'  r   r:  r;  r?  rT  rW  rO  rY  rd  rh  r^  rm  r   r   rr  r  r8  r  r   __classcell__rB   rB   r  rC   r     s2    4




3


 


5




specsr  	list[str]c                 C  s\   | du rg S t | tjrg S t | tr| r| dS g S t | tjjr't| S t	d| )z:Parse a plugins specification into a list of plugin names.N,zWPlugins may be specified as a sequence or a ','-separated string of plugin names. Got: )
r   r6  r7  rN   rX   collectionsabcr   r   r   )r  rB   rB   rC   r  i  s   
r  c                   @  s   e Zd Zdd ZdS )Notsetc                 C  s   dS )Nz<NOTSET>rB   rR   rB   rB   rC   __repr__  s   zNotset.__repr__N)r8   r9   r:   r  rB   rB   rB   rC   r  ~  r   r  package_filesIterable[str]Iterator[str]c                 c  s    t | } d}| D ]=}d|vo|d}|ddko|d}|r9tj|\}}|dkr8|ds8d}|V  q	|rFtj|}d}|V  q	|spg }| D ]}|d}	d	|	dd	 }
|
rd|
|
 qM|rrt|E d	H  d	S d	S d	S )
aM  Given an iterable of file names in a source distribution, return the "names" that should
    be marked for assertion rewrite.

    For example the package "pytest_mock/__init__.py" should be added as "pytest_mock" in
    the assertion rewrite mechanism.

    This function has to deal with dist-info based distributions and egg based distributions
    (which are still very much in use for "editable" installs).

    Here are the file names as seen in a dist-info based distribution:

        pytest_mock/__init__.py
        pytest_mock/_version.py
        pytest_mock/plugin.py
        pytest_mock.egg-info/PKG-INFO

    Here are the file names as seen in an egg based distribution:

        src/pytest_mock/__init__.py
        src/pytest_mock/_version.py
        src/pytest_mock/plugin.py
        src/pytest_mock.egg-info/PKG-INFO
        LICENSE
        setup.py

    We have to take in account those two distribution flavors in order to determine which
    names should be considered for assertion rewriting.

    More information:
        https://github.com/pytest-dev/pytest-mock/issues/167
    F/z.pyr   z__init__.pysetup__editable__TN)r   endswithcountrY   rE   splitextr!  dirnamerX   r   r   _iter_rewritable_modules)r  	seen_somefnis_simple_module
is_packagemodule_namer*  package_namenew_package_filespartsnew_fnrB   rB   rC   r    s:    

r  c                   @  s^  e Zd ZU dZeejddG dd dZG dd dej	Z
ded	< d
ddddZedddZedddZdddZdddZdd d!Zdd#d$Zdd'd(Z	
ddd-d.Zdd1d2Zedd3d4Zdd7d8Zedd9dd;d<Zdd>d?Zdd@dAZddFdGZddHdIZddJdKZ ddMdNZ!ddUdVZ"dddXdYZ#eddZdd\d]Z$dd^d_Z%dd`daZ&ddbdcZ'ddedfZ(ddgdhZ)dddidjZ*ddodpZ+ddsdtZ,ddvdwZ-dd{d|Z.dd}d~Z/dddZ0dddZ1e2dfdddZ3ddddZ4ddddZ5dZ6ded< dZ7ded< dZ8ded< ddddZ9e:dddZ;e:dddZ<dddZ=dddZ>d
S )r   a  Access to configuration values, pluginmanager and plugin hooks.

    :param PytestPluginManager pluginmanager:
        A pytest PluginManager.

    :param InvocationParams invocation_params:
        Object containing parameters regarding the :func:`pytest.main`
        invocation.
    T)frozenc                   @  s:   e Zd ZU dZded< 	 ded< 	 ded< 	 dddZdS )zConfig.InvocationParamsa  Holds parameters passed during :func:`pytest.main`.

        The object attributes are read-only.

        .. versionadded:: 5.1

        .. note::

            Note that the environment variable ``PYTEST_ADDOPTS`` and the ``addopts``
            ini option are handled by pytest, not being included in the ``args`` attribute.

            Plugins accessing ``InvocationParams`` must be aware of that.
        r   r\   r_   r^   rF   r   r  rI   rJ   c                C  s2   t | dt| t | d| t | d| d S )Nr\   r^   r   )object__setattr__tuple)rL   r\   r^   r   rB   rB   rC   rM     s   z Config.InvocationParams.__init__N)r\   r  r^   r_   r   rF   rI   rJ   )r8   r9   r:   r;   __annotations__rM   rB   rB   rB   rC   r     s   
 r   c                   @  s,   e Zd ZdZe Ze ZeZe Z	dS )zConfig.ArgsSourcezSIndicates the source of the test arguments.

        .. versionadded:: 7.2
        N)
r8   r9   r:   r;   enumautoARGSINVOCATION_DIRINCOVATION_DIR	TESTPATHSrB   rB   rB   rC   
ArgsSource  s    r  r0   cacheNr   r   r   r   InvocationParams | NonerI   rJ   c                C  s  ddl m} ddl m} |d u r| jdd tj d}t | _		 || _
	 |}|d| d| d| jd	d
| _|| _	 t | _	 | j| _| jjjd| _t| jj| _i | _d| _i | _t | _| j| d d| _| jjjt | j| jdd t!j"j#| _$g | _%d S )Nr   )FILE_OR_DIRr"   rB   r   z%(prog)s [options] [z] [z] [...]T)usage
processopt	_ispytestrg   pytestconfigF)parserr   r.  )&
argparsingr  r#   r   r   r   r   argparse	Namespaceoptionr   _processopt_parserr   r,   stash_storer  r  rj   r   rw   	_inicache_override_ini	_opt2dest
contextlib	ExitStack_cleanup_stackr   r  pytest_addoptionr4  r5  r   r  r  args_sourcer\   )rL   r   r   r  r#   _arB   rB   rC   rM     sD   



zConfig.__init__rF   c                 C     | j S )znThe path to the :ref:`rootdir <rootdir>`.

        :type: pathlib.Path

        .. versionadded:: 6.1
        )	_rootpathrR   rB   rB   rC   rC  D  s   zConfig.rootpathrE  c                 C  r  )zXThe path to the :ref:`configfile <configfiles>`.

        .. versionadded:: 6.1
        )_inipathrR   rB   rB   rC   inipathN  s   zConfig.inipathfuncCallable[[], None]c                 C  s   | j | dS )zAdd a function to be called when the config object gets out of
        use (usually coinciding with pytest_unconfigure).
        N)r  callback)rL   r  rB   rB   rC   add_cleanupV  s   zConfig.add_cleanupc                 C  s*   | j rJ d| _ | jjjt| dd d S )NTrf   r.  )r  rw   r?  r4  r5  rR   rB   rB   rC   _do_configure\  s   
zConfig._do_configurec                 C  s   z0| j rd| _ z| jj| d W g | jj_ng | jj_w W z| j  W t | _d S t | _w z| j  W t | _w t | _w )NFrf   )	r  rw   pytest_unconfigurer?  _call_historyr  closer  r  rR   rB   rB   rC   ry   a  s   zConfig._ensure_unconfigurer    c                 C  s   | j d}|d usJ |jS )Nterminalreporter)r   r9  _tw)rL   r  rB   rB   rC   get_terminal_writero  s
   zConfig.get_terminal_writerr\   r  c                 C  s   z|  | W | S  tyB   t| jddsd|v r%ddlm} ||   t| jdds4d|v s4d|v rA| j   t	j
d	  w )
NversionFz	--versionr   )showversionhelpz--helpz-hz8
NOTE: displaying only minimal help due to UsageError.

)parser   r   r  _pytest.helpconfigr  r  
_getparser
print_helprm   r   r  )rL   r   r\   r  rB   rB   rC   r   v  s"   	zConfig.pytest_cmdline_parseexcinfoExceptionInfo[BaseException]r  argparse.Namespace | Nonec                 C  s   |rt |ddrd}nd}|jdt |dd|d}| jj||d}t|s>t|d	D ]}tj	d
| d	 tj
  q,d S d S )N	fulltraceFlongnativeT
showlocals)funcargsr  rd   )excreprr  rh   zINTERNALERROR> )r   rr   rw   pytest_internalerroranyrN   rX   rm   rn   r  r   )rL   r  r  rd   r  resro   rB   rB   rC   notify_exception  s   zConfig.notify_exceptionnodeidrN   c                 C  sH   | j j| jkr"|d^}}| j| }t| j j|}d|g|}|S )NrJ  )r   r   rC  rX   r'   r   )rL   r  base_path_partnodeid_partfullpathrelative_pathrB   rB   rC   cwd_relative_nodeid  s   
zConfig.cwd_relative_nodeidc                 C  sB   t |}|jj| |j|dd |jjD ]}|j| q|S )z$Constructor usable for subprocesses.Faddopts)r   r  __dict__updater  r^   r   r   )clsoption_dictr\   rg   r\  rB   rB   rC   fromdictargs  s   zConfig.fromdictargsr  r!   c                 C  sT   |j |j D ]}|j| j|< qt|dr&t| j|js(t| j|j|j d S d S d S )Ndefault)_short_opts
_long_optsdestr  ry  r  setattrr  )rL   r  r   rB   rB   rC   r    s   
zConfig._processopt)r  early_configc                 C  sj   |j |jj|jj|d|jj|jdd\}}| jj	||jj|jj
|j|jj|jj|jj|dd d S )N	testpathsFr\   rA  r  rF  rC  r1  rI  )r\   rA  rB  rC  rD  rF  rG  rI  )_decide_argsknown_args_namespacefile_or_dirrA  getinir   r   rC  r   rT  rB  rD  rG  )rL   r  r\   r  rB   rB   rC   pytest_load_initial_conftests  s(   

z$Config.pytest_load_initial_conftestsrz  c                 C  s   | j j|t| jd\}}t|j|j| |jpd | jj	d\}}}|| _
|| _|| _t| j| j jd< t| j| j jd< | j ddd | j dd	 | j jd
ddg d | j jdddg d |jpdd| _d S )N	namespace)inifiler\   rootdir_cmd_argrF  rootdirr  r	  zExtra command line optionsr\   
minversionz!Minimally required pytest version
pythonpathpathszAdd paths to sys.path)rQ   r  r  required_pluginsz.Plugins that must be present for pytest to run)rQ   r  rB   )r  parse_known_and_unknown_argscopyr  r   inifilenamer  r   r   r   r  r  inicfgrN   rC  
extra_infor  addinioverride_inir  )rL   r\   nsunknown_argsrC  r  r(  rB   rB   rC   _initini  s4   
zConfig._initinic                 C  s   | j |\}}t|dd}t|ddpttjd}|dkr>ddl}z|j	| }W n t
y7   d}Y nw | || | | dS )	zInstall the PEP 302 import hook if using assertion rewriting.

        Needs to parse the --assert=<mode> option from the commandline
        and find all the installed plugins to mark them for rewriting
        by the importhook.
        
assertmodeplaindisable_plugin_autoloadFPYTEST_DISABLE_PLUGIN_AUTOLOADrewriter   N)r  r%  r   rV   rY   ri   rj   r  r   install_importhookSystemError_mark_plugins_for_rewrite_warn_about_missing_assertion)rL   r\   r,  r-  r   disable_autoloadr   rw   rB   rB   rC   _consider_importhook  s   
zConfig._consider_importhookrw   r/   r8  rV   c                 C  s@   || j _|rdS dd tj D }t|D ]}|| qdS )zGiven an importhook, mark for rewrite any top-level
        modules or packages in the distribution package for
        all pytest plugins.Nc                 s  s<    | ]}t d d |jD r|jpg D ]}t|V  qqdS )c                 s  s    | ]}|j d kV  qdS )r  N)group)r   eprB   rB   rC   	<genexpr>  s    z=Config._mark_plugins_for_rewrite.<locals>.<genexpr>.<genexpr>N)r  entry_pointsfilesrN   )r   distfilerB   rB   rC   r<    s    z3Config._mark_plugins_for_rewrite.<locals>.<genexpr>)r   r  rW   metadatadistributionsr  r  )rL   rw   r8  r  r   rB   rB   rC   r6    s   z Config._mark_plugins_for_rewritec                 C  s6   t | dD ]}tjdt| q| | j d S )Nr"  r   )r]  r  rm   rE   insertrN   r  _unconfigure_python_pathrV  rB   rB   rC   _configure_python_path$  s   zConfig._configure_python_pathc                 C  s2   |  dD ]}t|}|tjv rtj| qd S )Nr"  )r  rN   rm   rE   remove)rL   rE   path_strrB   rB   rC   rD  *  s   
zConfig._unconfigure_python_pathviac                 C  s6   || j _z| j j|t| jd W | j `|S | j `w )zValidate known args.r  )r  _config_source_hintr%  r&  r  )rL   r\   rH  rB   rB   rC   _validate_args0  s   zConfig._validate_argsrA  r  rF  rC  r1  tuple[list[str], ArgsSource]c                C  s   |rt jj}|}||fS ||kr>t jj}|r|}n'g }|D ]}	|ttj|	dd q|r=|s=|r=d}
| jt	|
dd ng }|sKt jj
}t|g}||fS )zDecide the args (initial paths/nodeids) to use given the relevant inputs.

        :param warn: Whether can issue warnings.

        :returns: The args and the args source. Guaranteed to be non-empty.
        T)	recursivezNo files were found in testpaths; consider removing or adjusting your testpaths configuration. Searching recursively from the current directory instead.r5   
stacklevel)r   r  r  r  extendsortedr[  iglobissue_config_time_warningr-   r  rN   )rL   r\   rA  r  rF  rC  r1  sourceresultrE   warning_textrB   rB   rC   r  <  s0   
zConfig._decide_argsr	  c              
   C  s  |rt jdd}t|r| t|d| |d d < | | |r2| | dd| |d d < | j	j
|t| jd| _|   | | |   | jj|dd t jd	sd| jjsd| jd
 | j  | j	j
|t| jd| _|   |   | jjd u r| jd urt| jj}nt| j}|| j_z| jj| || j	d W d S  ty } z| jj s| jj!r| j"t#d|j$ dd n W Y d }~d S d }~ww )NPYTEST_ADDOPTSr  zvia PYTEST_ADDOPTSr	  zvia addopts configr  Fr   r2  r  )r  r\   r  z"could not load initial conftests: r4   rM  )%rY   ri   rj   r|  rJ  shlexrX   r.  r  r  parse_known_argsr&  r  r  _checkversionr9  rE  r   r   r1  r  r  _validate_plugins_warn_about_skipped_pluginsrD  r  rN   r   rC  rw   r  rD   r  r  rR  r-   rE   )rL   r\   r	  env_addoptsrD  r|   rB   rB   rC   	_preparsei  s`   







zConfig._preparse)wrapperGenerator[None, object, object]c                 c  s    zd V W |    S |    w rK   )_validate_config_optionsrR   rB   rB   rC   pytest_collection  s   zConfig.pytest_collectionc                 C  s|   dd l }| jdd }|r:ddlm} t|ts!|| j d||||j	kr<|| j d| d|j	 dd S d S )Nr   r!  Versionz%: 'minversion' must be a single valuez: 'minversion' requires pytest-z, actual pytest-')
r2   r(  rj   packaging.versionrc  r   rN   r   r  r   )rL   r2   minverrc  rB   rB   rC   rY    s   

	zConfig._checkversionc                 C  s(   t |  D ]}| d| d qd S )NzUnknown config option: rh   )rP  _get_unknown_ini_keys_warn_or_fail_if_strict)rL   keyrB   rB   rC   r`    s   zConfig._validate_config_optionsc           
   	   C  s   t | d}|sd S ddlm} ddlm} ddlm} | j }dd |D }g }|D ]4}z||}	W n |yC   |	| Y q-w |	j
|vrO|	| q-|	jj|||	j
 dd	sa|	| q-|rntd
d|d S )Nr$  r   )InvalidRequirement)Requirementrb  c                 S  s   i | ]	\}}|j |jqS rB   )project_namer  )r   r*  r?  rB   rB   rC   
<dictcomp>  s    z,Config._validate_plugins.<locals>.<dictcomp>T)prereleaseszMissing required plugins: {}r   )rP  r  packaging.requirementsrj  rk  re  rc  r   list_plugin_distinfor   r   	specifiercontainsr   r   r   )
rL   r$  rj  rk  rc  plugin_infoplugin_dist_infomissing_pluginsrequired_pluginreqrB   rB   rC   rZ    s8   



zConfig._validate_pluginsr   c                 C  s&   | j jrt|| jt|dd d S )Nr5   rM  )r  strict_configr   rR  r-   )rL   r   rB   rB   rC   rh    s   zConfig._warn_or_fail_if_strictc                   s   | j j  fdd| jD S )Nc                   s   g | ]}| vr|qS rB   rB   )r   r   parser_inicfgrB   rC   
<listcomp>  s    z0Config._get_unknown_ini_keys.<locals>.<listcomp>)r  _inidictr(  rR   rB   ry  rC   rg    s   zConfig._get_unknown_ini_keysc                 C  s   | j g ks	J d| jjjt| jdd | j||d d| j_z%| jj	|| j
| j
d}| j|| jj| d| jj| jdd\| _ | _W d S  tyO   Y d S w )	Nz:can only parse cmdline args at most once per Config object)r   r.  r  Tr  r  r  )r\   rw   pytest_addhooksr4  r5  r   r]  r  after_preparseparse_setoptionr  r  r  rA  r  r   r   rC  r  r   )rL   r\   r	  rB   rB   rC   r    s.   

zConfig.parsewarningWarningrN  r   c                 C  s   | j drdS | jjpg }| d}tjdd}tdt| t	|| tj
||d W d   n1 s8w   Y  |rbt|d }|jj|j|jjf}| jjjt|d	 d
d|dd dS dS )a  Issue and handle a warning during the "configure" stage.

        During ``pytest_configure`` we can't capture warnings using the ``catch_warnings_for_item``
        function because it is not possible to have hook wrappers around ``pytest_configure``.

        This function is mainly intended for plugins that need to issue warnings during
        ``pytest_configure`` (or similar stages).

        :param warning: The warning instance.
        :param stacklevel: stacklevel forwarded to warnings.warn.
        r   NfilterwarningsT)recordalwaysrM  r   r   rg   r  )warning_messagewhenr  locationr.  )r   r  r  pythonwarningsr  r   catch_warningssimplefilterrQ   apply_warning_filtersr1  rm   	_getframef_codeco_filenamef_linenoco_namerw   pytest_warning_recordedr4  r5  )rL   r  rN  cmdline_filtersconfig_filtersrecordsframer  rB   rB   rC   rR    s*   


z Config.issue_config_time_warningr   ro   c                 C  s&   |  |}t|tsJ || dS )zAdd a line to an ini-file option. The option must have been
        declared but might not yet be set in which case the line becomes
        the first line in its value.N)r  r   r   r   )rL   r   ro   r\  rB   rB   rC   r>  +  s   
zConfig.addinivalue_liner   c                 C  s8   z| j | W S  ty   | | | j |< }| Y S w )al  Return configuration value from an :ref:`ini file <configfiles>`.

        If a configuration value is not defined in an
        :ref:`ini file <configfiles>`, then the ``default`` value provided while
        registering the configuration through
        :func:`parser.addini <pytest.Parser.addini>` will be returned.
        Please note that you can even provide ``None`` as a valid
        default value.

        If ``default`` is not provided while registering using
        :func:`parser.addini <pytest.Parser.addini>`, then a default value
        based on the ``type`` parameter passed to
        :func:`parser.addini <pytest.Parser.addini>` will be returned.
        The default values based on ``type`` are:
        ``paths``, ``pathlist``, ``args`` and ``linelist`` : empty list ``[]``
        ``bool`` : ``False``
        ``string`` : empty string ``""``
        ``int`` : ``0``
        ``float`` : ``0.0``

        If neither the ``default`` nor the ``type`` parameter is passed
        while registering the configuration through
        :func:`parser.addini <pytest.Parser.addini>`, then the configuration
        is treated as a string and a default empty string '' is returned.

        If the specified name hasn't been registered through a prior
        :func:`parser.addini <pytest.Parser.addini>` call (usually from a
        plugin), a ValueError is raised.
        )r  rf  _getini)rL   r   valrB   rB   rC   r  3  s   zConfig.getinirQ   valuer  c                 C  s   d| d| d|}t |)NzOption z  has unknown configuration type z with value )rz   )rL   r   rQ   r  r   rB   rB   rC   _getini_unknown_typeY  s   zConfig._getini_unknown_typec           	   
     s  z| j j| \}}}W n ty } ztd||d }~ww | |}|d u r<z| j| }W n ty;   | Y S w |}|dkrd| jd urK| jjn| jj	 t
|trYt|n|} fdd|D S |dkrtt
|trrt|S |S |dkrt
|trdd tdd	 |d
D S |S |dkrtt| S |dkr|S |dkrt
|tstd| d|d t|S |dkrt
|tstd| d|d t|S |d u r|S | |||S )Nzunknown configuration value: r#  c                   s   g | ]} | qS rB   rB   )r   r\  dprB   rC   r{        z"Config._getini.<locals>.<listcomp>r\   linelistc                 S  s   g | ]}|r|qS rB   rB   )r   trB   rB   rC   r{    r  c                 S  s   |   S rK   r~  )r\  rB   rB   rC   <lambda>  s    z Config._getini.<locals>.<lambda>rh   rV   stringr   z"Expected an int string for option z of type integer, but got: floatz#Expected a float string for option z of type float, but got: )r  r|  rf  rz   _get_override_ini_valuer(  r  r   r   r   r   rN   rW  rX   map
_strtoboolr~  r   r   r  r  )	rL   r   descriptionrQ   r  r|   override_valuer  input_valuesrB   r  rC   r  _  sd   




zConfig._getinirE   list[pathlib.Path] | Nonec                 C  s   z| j ||\}}W n
 ty   Y d S w |jd usJ t|jj}g }|D ] }t|tj	r6t|}n|
dtj}t|| }|| q(|S )Nr  )r   rh  rf  rq  r   r   r   r   rY   r   r2  rZ   r&   r   )rL   r   rE   rb  relrootsmodpathvaluesrelrootrB   rB   rC   _getconftest_pathlist  s   zConfig._getconftest_pathlistr)  c                 C  s`   d }| j D ](}z
|dd\}}W n ty& } z	td|d|d }~ww ||kr-|}q|S )Nr   r   z3-o/--override-ini expects option=value style (got: z).)r  rX   rz   r   )rL   r   r  
ini_configri  user_ini_valuer|   rB   rB   rC   r    s    

zConfig._get_override_ini_valueFr  skipc              
   C  s   | j ||}zt| j|}|du r|rt||W S  tyI } z#|tur.|W  Y d}~S |r=ddl}|d|d td||d}~ww )as  Return command line option value.

        :param name: Name of the option. You may also specify
            the literal ``--OPT`` option instead of the "dest" option name.
        :param default: Fallback value if no option of that name is **declared** via :hook:`pytest_addoption`.
            Note this parameter will be ignored when the option is **declared** even if the option's value is ``None``.
        :param skip: If ``True``, raise :func:`pytest.skip` if option is undeclared or has a ``None`` value.
            Note that even if ``True``, if a default was specified it will be returned instead of a skip.
        Nr   zno z option foundzno option named )	r  rj   r   r  r   notsetr2   r  rz   )rL   r   r  r  r  r|   r2   rB   rB   rC   	getoption  s   
zConfig.getoptionc                 C  s
   |  |S )z$Deprecated, use getoption() instead.r  rL   r   rE   rB   rB   rC   getvalue     
zConfig.getvaluec                 C  s   | j |ddS )z-Deprecated, use getoption(skip=True) instead.T)r  r  r  rB   rB   rC   getvalueorskip  r<  zConfig.getvalueorskip
assertionsr   VERBOSITY_ASSERTIONS
test_casesVERBOSITY_TEST_CASESr  _VERBOSITY_INI_DEFAULTverbosity_typec                 C  sb   | j ddd}t|tsJ |du r|S t|}|| jjvr!|S | |}|tjkr-|S t|S )a5  Retrieve the verbosity level for a fine-grained verbosity type.

        :param verbosity_type: Verbosity type to get level for. If a level is
            configured for the given type, that value will be returned. If the
            given type is not a known verbosity type, the global verbosity
            level will be returned. If the given type is None (default), the
            global verbosity level will be returned.

        To configure a level for a fine-grained verbosity type, the
        configuration file should have a setting for the configuration name
        and a numeric value for the verbosity level. A special value of "auto"
        can be used to explicitly use the global verbosity level.

        Example:

        .. code-block:: ini

            # content of pytest.ini
            [pytest]
            verbosity_assertions = 2

        .. code-block:: console

            pytest -v

        .. code-block:: python

            print(config.get_verbosity())  # 1
            print(config.get_verbosity(Config.VERBOSITY_ASSERTIONS))  # 2
        verboser   )r  N)	r  r   r   r   _verbosity_ini_namer  r|  r  r  )rL   r  global_levelini_namelevelrB   rB   rC   get_verbosity  s   


zConfig.get_verbosityc                 C  s
   d|  S )N
verbosity_rB   )r  rB   rB   rC   r    r  zConfig._verbosity_ini_namer  r#   r  c                 C  s   | j t||dtjd dS )a  Add a output verbosity configuration option for the given output type.

        :param parser: Parser for command line arguments and ini-file values.
        :param verbosity_type: Fine-grained verbosity category.
        :param help: Description of the output this type controls.

        The value should be retrieved via a call to
        :py:func:`config.get_verbosity(type) <pytest.Config.get_verbosity>`.
        r  )r  rQ   r  N)r*  r   r  r  )r  r  r  rB   rB   rC   _add_verbosity_ini  s   
zConfig._add_verbosity_inir   c                 C  s2   t  s|dkr
d}nd}| jt|dd d S d S )Nr0  zRASSERTIONS ARE NOT EXECUTED and FAILING TESTS WILL PASS.  Are you using python -O?zassertions not in test modules or plugins will be ignored because assert statements are not executed by the underlying Python interpreter (are you using python -O?)
r5   rM  )_assertion_supportedrR  r-   )rL   r   rU  rB   rB   rC   r7  .  s   
z$Config._warn_about_missing_assertionc                 C  s4   | j jD ]\}}| jtd|d| dd qd S )Nzskipped plugin rO   r4   rM  )r   r	  rR  r-   )rL   r  r   rB   rB   rC   r[  C  s   z"Config._warn_about_skipped_plugins)r   r   r   r  rI   rJ   )rI   rF   )rI   rE  )r  r  rI   rJ   r  )rI   r    )r   r   r\   r  rI   r   rK   )r  r  r  r  rI   rJ   )r  rN   rI   rN   )rI   r   )r  r!   rI   rJ   )r  r   rI   rJ   )r\   rz  rI   rJ   )rw   r/   r8  rV   rI   rJ   )r\   r  rH  rN   rI   r  )r\   r  rA  rV   r  r  rF  rF   rC  rF   r1  rV   rI   rK  )T)r\   r  r	  rV   rI   rJ   )rI   r_  )r   rN   rI   rJ   )rI   r  )r  r  rN  r   rI   rJ   )r   rN   ro   rN   rI   rJ   )r   rN   rI   r   )r   rN   rQ   rN   r  r  r  )r   rN   rE   rF   rI   r  )r   rN   rI   r)  )r   rN   r  r   r  rV   )r  r)  rI   r   )r  rN   rI   rN   )r  r#   r  rN   r  rN   rI   rJ   )r   rN   rI   rJ   )?r8   r9   r:   r;   r   dataclasses	dataclassr   r  Enumr  r  rM   propertyrC  r  r  r  ry   r  r   r  r  classmethodr  r  hookimplr  r.  r9  r6  rE  rD  rJ  r  r]  ra  rY  r`  rZ  rh  rg  r  rR  r>  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r7  r[  rB   rB   rB   rC   r     s|   
 

!=	






	






-<



!


#

&

@
.
c                   C  s   zJ  t y   Y dS w )NFT)rp  rB   rB   rB   rC   r  K  s
   r  rg   r@  TextIO | Noner    c                 C  s\   t |d}| jjdkrd|_n	| jjdkrd|_| jjdkr#d|_|S | jjdkr,d|_|S )zCreate a TerminalWriter instance configured according to the options
    in the config object.

    Every code which requires a TerminalWriter object and has access to a
    config object should use this function.
    )r@  yesTnoF)r    r  color	hasmarkupcode_highlight)rg   r@  r~   rB   rB   rC   create_terminal_writerT  s   
	r  r  c                 C  s.   |   } | dv r
dS | dv rdS td| )a  Convert a string representation of truth to True or False.

    True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values
    are 'n', 'no', 'f', 'false', 'off', and '0'.  Raises ValueError if
    'val' is anything else.

    .. note:: Copied from distutils.util.
    )yr  r  trueon1T)r  r  ffalseoff0Fzinvalid truth value )lowerrz   )r  rB   rB   rC   r  l  s   	r  2   )maxsizer  escape9tuple[warnings._ActionKind, str, type[Warning], str, int]c             
   C  s  d}t d|  d}| d}t|dkr,d}t dt| d| d	}t|j|d
t|dk r=|d t|dk s2dd |D \}}}	}
}zt|}W n tjyh } zt|jt	|d
dd}~ww zt
|	}W n ty   t }|jdd}t|j|d
dw |r|rt|}|
r|rt|
d }
|rzt|}|dk rtdW n ty } zt|jd|d| d
dd}~ww d}zt| t|
 W n tjy } zt|jd|jd| d
dd}~ww ||||
|fS )zParse a warnings filter string.

    This is copied from warnings._setoption with the following changes:

    * Does not apply the filter.
    * Escaping is optional.
    * Raises UsageError so we get nice error messages on failure.
    TzF        while parsing the following warning configuration:

          z8

        This error occurred:

        {error}
        :r7   zJhttps://docs.python.org/3/library/warnings.html#describing-warning-filtersz            Too many fields (z), expected at most 5 separated by colons:

              action:message:category:module:line

            For more information please consult: z
            )errorr  c                 s  s    | ]}|  V  qd S rK   r  )r   srB   rB   rC   r<    s    z'parse_warning_filter.<locals>.<genexpr>Nr  )rd   z\Zr   znumber is negativezinvalid lineno rO   zInvalid regex )r	   rX   r|  r   r   r   r   
_getaction_OptionErrorrN   _resolve_warning_categoryrH   r   from_currentrr   rer  r   rz   compiler  pattern)r  r  __tracebackhide__error_templater  doc_urlr  action_r   	category_modulelineno_actionr|   categoryr}   exception_textlinenorB   rB   rC   parse_warning_filter~  s   
	


r  r  type[Warning]c                 C  sr   d}| st S d| vrddl}| }n| d\}}}t|dd|g}t||}t|t s2t| dttt  |S )z
    Copied from warnings._getcategory, but changed so it lets exceptions (specially ImportErrors)
    propagate so we can get access to their tracebacks (#9218).
    T.r   Nz is not a Warning subclass)	r  builtins
rpartitionr  r   
issubclassr   r   rQ   )r  r  r   klassr  r*  catrB   rB   rC   r    s   

r  r  r  rJ   c                 C  s<   | D ]}t jt|dd  q|D ]}t jt|dd  qdS )z8Applies pytest-configured filters to the warnings moduleF)r  TN)r   r  r  )r  r  r  rB   rB   rC   r    s
   r  )rT   rU   rI   rV   )NN)r\   r]   r^   r_   rI   r`   )rI   r   )rE   rN   r   rN   rI   rN   )r\   r   r^   r_   rI   r   )rI   r   )r\   r]   r^   r_   rI   r   )rE   rF   rI   rF   )r   r   r   rN   r   r   rI   r   )r  r  rI   r  )r  r  rI   r  )rI   rV   rK   )rg   r   r@  r  rI   r    )r  rN   rI   rV   )r  rN   r  rV   rI   r  )r  rN   rI   r  )r  r  r  r  rI   rJ   )yr;   
__future__r   r  collections.abcr  r   r   r   r   r   r  r&  r  r  	functoolsr   r[  importlib.metadatarW   r   rY   r   r  rW  rm   textwrapr	   r6  r
   typingr   r   r   r   r   r   r   r   pluggyr   r   r   r   r   compatr   
exceptionsr   r   	findpathsr   r   r   _pytest._coder   r   _pytest._code.coder   _pytest._ior    _pytest.config.argparsingr!   r#   _pytest.deprecated_pytest.hookspec_pytest.outcomesr$   r%   _pytest.pathlibr&   r'   r(   r)   r*   r+   _pytest.stashr,   _pytest.warning_typesr-   r.   _pytest.assertion.rewriter/   _pytest.cacheproviderr0   _pytest.terminalr1   r  r  r  r  IntEnumr3   rH   rD   r[   r   r   r   r   r   r  r   r  r   r   rk   r   r   r   r  r  r  r  r   r  r  r  r  r  r  rB   rB   rB   rC   <module>   sf  	

7

	


 
    
d
A       




N