o
    Zh)-                     @   s   d dl Z d dlZd dlZd dlZd dlZeedoejdkZeej	Z
ejdd Zdd Zejdd	 Zejd
d Zejdddd Zejdddd ZdefddZdefddZeZdd Zejdddd Zejdddd ZdS )     Nversion_tuple)   r   c                    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   fdd}W n, tyz   t jd	d
kr`Y dS zddl m} W n tyw   ddlm} Y nw Y nw z| }W n
 ty   Y dS w |r|S dS )NZPYTEST_XDIST_AUTO_NUM_WORKERSzHPYTEST_XDIST_AUTO_NUM_WORKERS is not a number: {env_var!r}. Ignoring it.r   logical)r   sched_getaffinityc                      s   t  dS )Nr   )len r   r   C/var/www/html/lang_env/lib/python3.10/site-packages/xdist/plugin.py	cpu_count%   s   z0pytest_xdist_auto_num_workers.<locals>.cpu_countZTRAVIStrue   )r
      )osenvirongetint
ValueErrorwarningswarnpsutilImportErroroptionnumprocessesr
   r   multiprocessingNotImplementedError)configenv_varr   Zuse_logicalcountr
   nr   r   r	   pytest_xdist_auto_num_workers   sJ   

r   c                 C   s    | dv r| S | d urt | S d S )Nautor   )r   )sr   r   r	   parse_numprocesses7   s
   r#   c              	   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d0d1trwd2nd3d4 | jd5d6trd2nd3d4 | jd7trd2nd3d8d9 d S ):Nxdistz"distributed and subprocess testingz-nz--numprocessesr   storezShortcut for '--dist=load --tx=NUM*popen'. With 'auto', attempt to detect physical CPU count. With 'logical', detect logical CPU count. If physical CPU count cannot be found, falls back to logical count. This will be 0 when used with --pdb.)destmetavaractiontypehelpz--maxprocessesmaxprocesseszWlimit the maximum number of workers to process the tests when using --numprocesses=autoz--max-worker-restartZmaxworkerrestartzbmaximum number of workers that can be restarted when crashed (set to zero to disable this feature))r(   defaultr&   r*   z--distZdistmode)ZeachloadZ	loadscopeZloadfileZ	loadgroupZ	workstealnodistr.   ax  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 rebalance when any worker runs out of tests.

(default) no: run tests inprocess, don't distribute.)r'   r(   choicesr&   r,   r*   z--txtxappendZ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)r&   r(   r,   r'   r*   z-d
store_truedistloadFz/load-balance tests.  shortcut for '--dist=load')r(   r&   r,   r*   z
--rsyncdirDIRz.add directory for rsyncing to remote tx nodes.)r(   r,   r'   r*   z--rsyncignoreZGLOBz<add expression for ignores when rsyncing to remote tx nodes.z--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.)r(   r*   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.)r(   r)   r*   	rsyncdirszFlist of (relative) paths to be rsynced for remote distributed testing.pathsZpathlist)r)   Zrsyncignorez?list of (relative) glob-style paths to be ignored for rsyncing.looponfailrootsz=directories to check for changes. Default: current directory.)r)   r*   )ZgetgroupZ
_addoptionr#   Z	addoptionr   ZaddiniPYTEST_GTE_7)parsergroupr   r   r	   pytest_addoption>   s   	




r<   c                 C   s   ddl m} | | d S )Nr   )newhooks)r$   r=   Zadd_hookspecs)pluginmanagerr=   r   r   r	   pytest_addhooks   s   r?   T)Ztrylastc                 C   s   d}|  d| | drd S | ddkr7| dr7ddlm} || }| j|d	 | jd
}|r7d|_| dd sB| 	drLt
d}| |d | dd sW| 	drct
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/   r.   r1   r   )DSessionZdsessionZterminalreporterFZ
looponfailr8   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   Zrsyncdirr6   zThe --rsyncdir command line argument and rsyncdirs config variable are deprecated.
The rsync feature will be removed in pytest-xdist 4.0.)Zaddinivalue_linegetvalue	getoptionZxdist.dsessionrB   r>   registerZ	getpluginZ
showfspathZgetiniDeprecationWarningZissue_config_time_warning)r   Zconfig_linerB   sessiontrwarningr   r   r	   pytest_configure   s.   
rJ   )Ztryfirstc                 C   s   |  dd}| jjdv r"|rd| j_d| j_n| jj| d}|| j_| jjrF| jjdkr0d| j_| jj}| jjr?t|| jj}dg| | j_| jj	rNd| j_| j
}|d	sb|d
dkrd|rftdd S d S d S )NusepdbFr    r   r.   )r   r-   popenrA   r/   zG--pdb is incompatible with distributing tests; try using -n0 or -nauto.)rD   r   r   r/   hookr   r+   minr1   r4   rC   pytestZ
UsageError)r   rK   Zauto_num_cpusr   valr   r   r	   pytest_cmdline_main   s,   
rQ   returnc                 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   Zrequest_or_sessionr   r   r	   is_xdist_worker  s   rV   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.   )rV   r   r   r/   rU   r   r   r	   is_xdist_controller'  s   
	rW   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
    rS   ZworkeridZmaster)rT   r   rS   rU   r   r   r	   get_xdist_worker_id9  s   	rX   rG   )scopec                 C   s   t | S )zkReturn the id of the current worker ('gw0', 'gw1', etc) or 'master'
    if running on the master node.
    )rX   requestr   r   r	   	worker_idI  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.rS   Z
testrunuid)rT   r   rS   uuiduuid4hexrZ   r   r   r	   testrun_uidR  s   
r`   )r   r]   sysr   rO   rT   r   r9   listpathZ	_sys_pathZhookimplr   r#   r<   r?   rJ   rQ   boolrV   rW   Zis_xdist_masterrX   Zfixturer\   r`   r   r   r   r	   <module>   s6    

(
 



&



