a
    4ñ»ja6  ã                   @  sT  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dddœdd„ƒZd	d
dœdd„Zejdddœdd„ƒZejdddœdd„ƒZejdd�dddœdd„ƒZdddœdd„Zejdd�dddœdd „ƒZd!dd"œd#d$„Zd!dd"œd%d&„ZeZd!d	d"œd'd(„Zejd)d*�d+d	d,œd-d.„ƒZejd)d*�d+d	d,œd/d0„ƒZdS )1é    )ÚannotationsN)ÚLiteralzpytest.ConfigÚint)ÚconfigÚreturnc                   s,  t j d¡}|r8z
t|ƒW S  ty6   t d¡ Y n0 zdd l}W n tyV   Y n*0 | j	j
dk}|j|d�pv| ¡ }|r€|S z"ddl m‰  ddœ‡ fd	d
„}W nX tyú   t j d¡dkrÆY dS zddl m} W n tyô   ddlm} Y n0 Y n0 z
|ƒ }W n t�y   Y dS 0 |�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_getaffinityr   )r   c                     s   t ˆ dƒƒS )Nr   )Úlen© r   r   ú2E:\soccer\ml_env\Lib\site-packages\xdist/plugin.pyÚ	cpu_count&   s    z0pytest_xdist_auto_num_workers.<locals>.cpu_countZTRAVISÚtrueé   )r   é   )ÚosÚenvironÚgetr   Ú
ValueErrorÚwarningsÚwarnÚpsutilÚImportErrorÚoptionÚnumprocessesr   r	   ÚmultiprocessingÚNotImplementedError)r   Úenv_varr   Zuse_logicalÚcountr   Únr   r   r   Úpytest_xdist_auto_num_workers   s>    
ÿ

r    Ústrz int | Literal['auto', 'logical'])Úsr   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%   zpytest.ParserÚNone)Úparserr   c              	   C  sN  |   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ddd� |jddddd � |jd!d"d#g d$d%d&� |jd'd(d#g d$d)d&� |jd*dd+d,d-d.� |jd/d#g d0d1d2� |jd3d#g d4d5d2� |jd6dd7d8� |jd9dtd:d;� | jd<d=d>d?� | jd@dAd>d?� | jdBd>dCdD� d S )ENÚ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-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Údistr2   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.)r+   r,   Úchoicesr*   r0   r.   z--loadscope-reorderZloadscopereorderÚ
store_trueTa	  Pytest-xdist will default reorder tests by number of tests per scope when used in conjunction with loadscope.
This option will enable loadscope reorder which will improve the parallelism of the test suite.
However, the partial order of tests might not be retained.
)r*   r,   r0   r.   z--no-loadscope-reorderÚstore_falsea6  Pytest-xdist will default reorder tests by number of tests per scope when used in conjunction with loadscope.
This option will disable loadscope reorder, and the partial order of tests can be retained.
This is useful when pytest-xdist is used together with other plugins that specify tests in a specific order.)r*   r,   r.   z--txÚtxÚappendZxspecz™Add 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,   r0   r+   r.   z--pxZpxz—Add a proxy gateway to pass to test execution environments using `via`. Example:
--px id=my_proxy//socket=192.168.1.102:8888 --tx 5*popen//via=my_proxyz-dÚdistloadFz/Load-balance tests. Shortcut for '--dist=load'.)r,   r*   r0   r.   z
--rsyncdirÚDIRz-Add directory for rsyncing to remote tx nodes)r,   r0   r+   r.   z--rsyncignoreZGLOBz;Add expression for ignores when rsyncing to remote tx nodesz--testrunuidz°Provide 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.Úpaths)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)r'   Úgroupr   r   r   Úpytest_addoption?   sÜ    ùú	û	ðúûùùûûûü
ûýýýr?   zpytest.PytestPluginManager)Úpluginmanagerr   c                 C  s   ddl m} |  |¡ d S )Nr   )Únewhooks)r(   rA   Zadd_hookspecs)r@   rA   r   r   r   Úpytest_addhooksø   s    rB   T)Ztrylastc                 C  s¶   d}|   d|¡ |  d¡rd S t| ƒr^ddlm} || ƒ}| j |d¡ | j d¡}|r^d|_|  	d	d ¡st|  
d
¡rˆtdƒ}|  |d¡ |  	dd ¡sž|  
d¡r²tdƒ}|  |d¡ d S )Nzuxdist_group: specify group for tests should run in same session.in relation to one another. Provided by pytest-xdist.ÚmarkersÚcollectonlyr   )ÚDSessionZdsessionZterminalreporterFZ
looponfailr=   z˜The --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rsyncdirr;   z‰The --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Ú_is_distribution_modeZxdist.dsessionrE   r@   ÚregisterZ	getpluginZ
showfspathÚ	getoptionZgetiniÚDeprecationWarningZissue_config_time_warning)r   Zconfig_linerE   ÚsessionÚtrÚwarningr   r   r   Úpytest_configure  s,    ÿ
ÿÿrN   Úboolc                 C  s   |   d¡dkot|   d¡ƒS )z Whether distribution mode is on.r3   r2   r7   )rI   rO   ©r   r   r   r   rG   +  s    rG   )Ztryfirstc                 C  sà   | j jrd| j _|  dd¡}| j jdv rT|r>d| j _d| j _n| jj| d�}|| j _| j jrœ| j jdkrpd| j _| j j}| j jrŽt|| j jƒ}dg| | j _	| j jdkr¸d| j _g | j _	| j
}|d	ƒsÜt| ƒrÜ|rÜt d
¡‚d S )Nr1   ÚusepdbFr#   r   r2   rP   ÚpopenrD   zG--pdb is incompatible with distributing tests; try using -n0 or -nauto.)r   r9   r3   rI   r   Úhookr    r/   Úminr7   rF   rG   ÚpytestZ
UsageError)r   rQ   Zauto_num_cpusr   Úvalr   r   r   Úpytest_cmdline_main0  s0    
ÿrW   z&pytest.FixtureRequest | pytest.Session)Úrequest_or_sessionr   c                 C  s   t | jdƒS )zŒReturn `True` if this is an xdist worker, `False` otherwise.

    :param request_or_session: the `pytest` `request` or `session` object
    Úworkerinput)Úhasattrr   ©rX   r   r   r   Úis_xdist_workerV  s    r\   c                 C  s   t | ƒ o| jjjdkS )zòReturn `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
    r2   )r\   r   r   r3   r[   r   r   r   Úis_xdist_controller`  s    
þr]   c                 C  s$   t | jdƒr| jjd }|S 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
    rY   ÚworkeridZmasterN)rZ   r   rY   )rX   r^   r   r   r   Úget_xdist_worker_idt  s    r_   rK   )Úscopezpytest.FixtureRequest)Úrequestr   c                 C  s   t | ƒS )zkReturn the id of the current worker ('gw0', 'gw1', etc) or 'master'
    if running on the master node.
    )r_   )ra   r   r   r   Ú	worker_id‡  s    rb   c                 C  s*   t | jdƒr| jjd }|S t ¡ jS dS )z)Return the unique id of the current test.rY   Z
testrunuidN)rZ   r   rY   ÚuuidÚuuid4Úhex)ra   Z	testrunidr   r   r   Útestrun_uid�  s    rf   )Ú
__future__r   r   ÚsysÚtypingr   rc   r   rU   ÚlistÚpathZ	_sys_pathZhookimplr    r%   r?   rB   rN   rG   rW   r\   r]   Zis_xdist_masterr_   Zfixturerb   rf   r   r   r   r   Ú<module>   s8   
( 9
&
%


