o
    %if0                     @  s  d dl m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e	ej
Zejd2dd	Zd3ddZejd4ddZejd5ddZejddd6ddZd7ddZejddd6d d!Zd8d$d%Zd8d&d'ZeZd9d(d)Zejd*d+d:d.d/Zejd*d+d:d0d1ZdS );    )annotationsN)Literalconfigpytest.Configreturnintc                   s$  t jd}|rzt|W S  ty   td Y nw zdd l}W n	 ty+   Y nw | j	j
dk}|j|dp;| }|r@|S zddl m  d fd	d
}W n, ty{   t jddkraY dS zddl m} W n tyx   ddlm} Y nw Y nw z| }W n
 ty   Y dS w |r|S dS )NPYTEST_XDIST_AUTO_NUM_WORKERSzHPYTEST_XDIST_AUTO_NUM_WORKERS is not a number: {env_var!r}. Ignoring it.r   logical)r	   sched_getaffinityr   r   c                     s   t  dS )Nr   )len r
   r   E/var/www/html/corbot_env/lib/python3.10/site-packages/xdist/plugin.py	cpu_count&   s   z0pytest_xdist_auto_num_workers.<locals>.cpu_countTRAVIStrue   )r      )r   r   )osenvirongetr   
ValueErrorwarningswarnpsutilImportErroroptionnumprocessesr   r   multiprocessingNotImplementedError)r   env_varr   use_logicalcountr   nr   r
   r   pytest_xdist_auto_num_workers   sJ   

r$   sstr int | Literal['auto', 'logical']c                 C  s    | dv r| S | d urt | S d S )Nautor	   )r   )r%   r   r   r   parse_numprocesses8   s
   r*   parserpytest.ParserNonec              	   C  s  |  dd}|jdddddtdd |jd	d
d
dtdd |jddd ddd |jdddg ddddd |jdddg ddd |jdddd d!d" |jd#dg d$d%d& |jd'dg d(d)d& |jd*dd+d, |jd-dtd.d/ | jd0d1d2d3 | jd4d5d2d3 | jd6d2d7d8 d S )9Nxdistz"distributed and subprocess testingz-nz--numprocessesr   storea$  Shortcut for '--dist=load --tx=NUM*popen'.
With 'logical', attempt to detect logical CPU count (requires psutil, falls back to 'auto').
With 'auto', attempt to detect physical CPU count. If physical CPU count cannot be determined, falls back to 1.
Forced to 0 (disabled) when used with --pdb.)destmetavaractiontypehelpz--maxprocessesmaxprocesseszkLimit the maximum number of workers to process the tests when using --numprocesses with 'auto' or 'logical'z--max-worker-restartmaxworkerrestartzbMaximum number of workers that can be restarted when crashed (set to zero to disable this feature))r2   defaultr0   r4   z--distdistmode)eachload	loadscopeloadfile	loadgroup	workstealnodistr?   a{  Set mode for distributing tests to exec environments.

each: Send each test to all available environments.

load: Load balance by sending any pending test to any available environment.

loadscope: Load balance by sending pending groups of tests in the same scope to any available environment.

loadfile: Load balance by sending test grouped by file to any available environment.

loadgroup: Like 'load', but sends tests marked with 'xdist_group' to the same worker.

worksteal: Split the test suite between available environments, then re-balance when any worker runs out of tests.

(default) no: Run tests inprocess, don't distribute.)r1   r2   choicesr0   r7   r4   z--txtxappendxspeczAdd a test execution environment. Some examples:
--tx popen//python=python2.5 --tx socket=192.168.1.102:8888
--tx ssh=user@codespeak.net//chdir=testcache)r0   r2   r7   r1   r4   z-d
store_truedistloadFz/Load-balance tests. Shortcut for '--dist=load'.)r2   r0   r7   r4   z
--rsyncdirDIRz-Add directory for rsyncing to remote tx nodes)r2   r7   r1   r4   z--rsyncignoreGLOBz;Add expression for ignores when rsyncing to remote tx nodesz--testrunuidzProvide an identifier shared amongst all workers as the value of the 'testrun_uid' fixture.
If not provided, 'testrun_uid' is filled with a new unique string on every test run.)r2   r4   z--maxschedchunka  Maximum number of tests scheduled in one step for --dist=load.
Setting it to 1 will force pytest to send tests to workers one by one - might be useful for a small number of slow tests.
Larger numbers will allow the scheduler to submit consecutive chunks of tests to workers - allows reusing fixtures.
Due to implementation reasons, at least 2 tests are scheduled per worker at the start. Only later tests can be scheduled one by one.
Unlimited if not set.)r2   r3   r4   	rsyncdirszFlist of (relative) paths to be rsynced for remote distributed testing.paths)r3   rsyncignorez?list of (relative) glob-style paths to be ignored for rsyncing.looponfailrootsz=directories to check for changes. Default: current directory.)r3   r4   )getgroup
_addoptionr*   	addoptionr   addini)r+   groupr   r   r   pytest_addoption?   s   		

rR   pluginmanagerpytest.PytestPluginManagerc                 C  s   ddl m} | | d S )Nr   )newhooks)r.   rU   add_hookspecs)rS   rU   r   r   r   pytest_addhooks   s   rW   T)trylastc                 C  s   d}|  d| | drd S t| r/ddlm} || }| j|d | jd}|r/d|_| 	d	d s:| 
d
rDtd}| |d | 	dd sO| 
dr[td}| |d d S d S )Nzuxdist_group: specify group for tests should run in same session.in relation to one another. Provided by pytest-xdist.markerscollectonlyr   )DSessiondsessionterminalreporterF
looponfailrL   zThe --looponfail command line argument and looponfailroots config variable are deprecated.
The loop-on-fail feature will be removed in pytest-xdist 4.0.r   rsyncdirrI   zThe --rsyncdir command line argument and rsyncdirs config variable are deprecated.
The rsync feature will be removed in pytest-xdist 4.0.)addinivalue_linegetvalue_is_distribution_modexdist.dsessionr[   rS   register	getplugin
showfspath	getoptiongetiniDeprecationWarningissue_config_time_warning)r   config_liner[   sessiontrwarningr   r   r   pytest_configure   s.   
ro   boolc                 C  s   |  ddkot|  dS )z Whether distribution mode is on.r@   r?   rB   )rg   rp   r   r   r   r   rb     s   rb   )tryfirstc                 C  s   | j jrd| j _| dd}| j jdv r*|rd| j _d| j _n| jj| d}|| j _| j jrN| j jdkr8d| j _| j j}| j jrGt|| j j}dg| | j _	| j jdkr\d| j _g | j _	| j
}|d	snt| rp|rrtd
d S d S d S )Nr:   usepdbFr(   r   r?   rq   popenrZ   zG--pdb is incompatible with distributing tests; try using -n0 or -nauto.)r   rF   r@   rg   r   hookr$   r5   minrB   ra   rb   pytest
UsageError)r   rs   auto_num_cpusr   valr   r   r   pytest_cmdline_main  s2   
r{   request_or_session&pytest.FixtureRequest | pytest.Sessionc                 C  s   t | jdS )zReturn `True` if this is an xdist worker, `False` otherwise.

    :param request_or_session: the `pytest` `request` or `session` object
    workerinput)hasattrr   r|   r   r   r   is_xdist_worker1  s   r   c                 C  s   t |  o| jjjdkS )zReturn `True` if this is the xdist controller, `False` otherwise.

    Note: this method also returns `False` when distribution has not been
    activated at all.

    :param request_or_session: the `pytest` `request` or `session` object
    r?   )r   r   r   r@   r   r   r   r   is_xdist_controller;  s   
r   c                 C  s    t | jdr| jjd }|S dS )a*  Return the id of the current worker ('gw0', 'gw1', etc) or 'master'
    if running on the controller node.

    If not distributing tests (for example passing `-n0` or not passing `-n` at all)
    also return 'master'.

    :param request_or_session: the `pytest` `request` or `session` object
    r~   workeridmaster)r   r   r~   )r|   r   r   r   r   get_xdist_worker_idO  s   r   rl   )scoperequestpytest.FixtureRequestc                 C  s   t | S )zkReturn the id of the current worker ('gw0', 'gw1', etc) or 'master'
    if running on the master node.
    )r   )r   r   r   r   	worker_idb  s   r   c                 C  s&   t | jdr| jjd }|S t jS )z)Return the unique id of the current test.r~   
testrunuid)r   r   r~   uuiduuid4hex)r   	testrunidr   r   r   testrun_uidk  s   
r   )r   r   r   r   )r%   r&   r   r'   )r+   r,   r   r-   )rS   rT   r   r-   )r   r   r   r-   )r   r   r   rp   )r|   r}   r   rp   )r|   r}   r   r&   )r   r   r   r&   )
__future__r   r   systypingr   r   r   rw   listpath	_sys_pathhookimplr$   r*   rR   rW   ro   rb   r{   r   r   is_xdist_masterr   fixturer   r   r   r   r   r   <module>   s:    

( 

&

%




