a
    ij                     @  s   d Z ddlmZ ddlZddlZddlmZmZ ddlZdZ	ej
je	ddZdaejG dd	 d	Zejd
ddddZejddddZdS )zPytest utils.    )annotationsN)AnyIteratorFzNon-hermetic test skipped.)reasonc                   @  s.   e Zd ZU dZded< ejedZded< dS )_SubtestContextzContext of a test using `subtests` fixture.

  Attributes:
    subtests: Reference to the original `subtests` fixture output
    names: Stack of current nested `subtests.test`
  r   subtests)default_factoryz	list[str]namesN)	__name__
__module____qualname____doc____annotations__dataclassesfieldlistr	    r   r   O/home/ghrups/robot-bench/.venv/lib/python3.9/site-packages/etils/epy/testing.pyr   *   s   
r   strzIterator[None])namereturnc                 c  s   t stdt| } t j|  dt j}zNt jj|d dV  W d   n1 sX0    Y  W t j }|| ksJ nt j }|| ksJ 0 dS )zFContextmanager for a new subtest. To use with `with_subtests` fixture.zJ`epy.testing.subtest` can only be called inside a `with_subtests` context./)msgN)	_curr_contextAssertionErrorr   r	   appendjoinr   testpop)r   Zsubtest_nameZout_namer   r   r   subtest7   s    &

r   )r   c                 c  s8   t durtdt| d}z|a dV  W da nda 0 dS )af  Fixture which activate subtests for global usage.

  This fixture is a small wrapper around `subtests` pytest extension fixing
  2 issues:

  * Global usage: https://github.com/pytest-dev/pytest-subtests/issues/44
  * Nested report: https://github.com/pytest-dev/pytest-subtests/issues/45

  Usage:

  ```python
  with_subtests = epy.testing.with_subtests  # Required to register the fixture

  @pytest.mark.usefixtures('with_subtests')
  def my_test():
    with epy.testing.subtest('a'):
      with epy.testing.subtest('b'):
        assert False
  ```

  Args:
    subtests: Subtest fixture

  Yields:
    None
  NzConflicting `subtests` context.)r   )r   r   r   )r   Znew_contextr   r   r   with_subtestsJ   s    
r    )r   
__future__r   
contextlibr   typingr   r   ZpytestZ_SKIP_NON_HERMETICmarkZskipifZnon_hermeticr   	dataclassr   contextmanagerr   Zfixturer    r   r   r   r   <module>   s"   