관리-도구
편집 파일: attrib.cpython-38.pyc
U )�e�% � @ s� d Z ddlZddlZddlZddlZddlmZ ddlmZ ddlm Z ddl Z e�d�Zej dkZdd � Zddd�ZG d d� d�ZG dd� de�ZdS )a Attribute selector plugin. Oftentimes when testing you will want to select tests based on criteria rather then simply by filename. For example, you might want to run all tests except for the slow ones. You can do this with the Attribute selector plugin by setting attributes on your test methods. Here is an example: .. code-block:: python def test_big_download(): import urllib # commence slowness... test_big_download.slow = 1 Once you've assigned an attribute ``slow = 1`` you can exclude that test and all other tests having the slow attribute by running :: $ nosetests -a '!slow' There is also a decorator available for you that will set attributes. Here's how to set ``slow=1`` like above with the decorator: .. code-block:: python from nose.plugins.attrib import attr @attr('slow') def test_big_download(): import urllib # commence slowness... And here's how to set an attribute with a specific value: .. code-block:: python from nose.plugins.attrib import attr @attr(speed='slow') def test_big_download(): import urllib # commence slowness... This test could be run with :: $ nosetests -a speed=slow In Python 2.6 and higher, ``@attr`` can be used on a class to set attributes on all its test methods at once. For example: .. code-block:: python from nose.plugins.attrib import attr @attr(speed='slow') class MyTestCase: def test_long_integration(self): pass def test_end_to_end_something(self): pass Below is a reference to the different syntaxes available. Simple syntax ------------- Examples of using the ``-a`` and ``--attr`` options: * ``nosetests -a status=stable`` Only runs tests with attribute "status" having value "stable" * ``nosetests -a priority=2,status=stable`` Runs tests having both attributes and values * ``nosetests -a priority=2 -a slow`` Runs tests that match either attribute * ``nosetests -a tags=http`` If a test's ``tags`` attribute was a list and it contained the value ``http`` then it would be run * ``nosetests -a slow`` Runs tests with the attribute ``slow`` if its value does not equal False (False, [], "", etc...) * ``nosetests -a '!slow'`` Runs tests that do NOT have the attribute ``slow`` or have a ``slow`` attribute that is equal to False **NOTE**: if your shell (like bash) interprets '!' as a special character make sure to put single quotes around it. Expression Evaluation --------------------- Examples using the ``-A`` and ``--eval-attr`` options: * ``nosetests -A "not slow"`` Evaluates the Python expression "not slow" and runs the test if True * ``nosetests -A "(priority > 5) and not slow"`` Evaluates a complex Python expression and runs the test if True � N)� isfunction)�Plugin)�tolistznose.plugins.attrib)� � c s � �fdd�}|S )zgDecorator that adds attributes to classes or functions for use with the Attribute (-a) plugin. c s8 � D ]}t | |d� q��� D ]\}}t | ||� q| S )NT)�setattr�items)�ob�name�value��args�kwargs� �A/opt/hc_python/lib/python3.8/site-packages/nose/plugins/attrib.py�wrap_obw s zattr.<locals>.wrap_obr )r r r r r r �attrs s r Fc C s>