Your IP : 216.73.216.213
B
�d{T>� � @ s� d Z ddlmZ dZdZdZdZddlZddlZddl Z ddl
mZ ddl
m
Z
mZ ddlZddlZdd lmZmZ dd
lmZ ddlmZ ddlmZ dd
lmZmZ ddlmZmZ ddlm Z ddl!Z!ddlZ"e#e"dd��syddl$m%Z& W n e'k
�r e�(d� Y nX nddl)m%Z& y ddl*Z*ddl+m,Z,m-Z- dZ.W n e'k
�r\ dZ.Y nX dZ/edDdd��Z0dd� Z1G dd� de2�Z3e3j4Z4e3j5Z5dd� Z6e �7d�Z8dd� Z9e �7d �Z:d!d"� Z;d#d$� Z<e�=� fd%d&�Z>G d'd(� d(e2�Z?d)d*� Z@G d+d,� d,e2�ZAG d-d.� d.eA�ZBd/d0� ZCd1d2� ZDd3d4� ZEG d5d6� d6ejF�ZGG d7d8� d8ejH�ZIG d9d:� d:ejJ�ZKdEd;d<�ZLdFd=d>�ZMejNd?k�r�dGd@d<�ZLdAdB� ZOejPe_QeIe_HeKe_JeGe_FejNdCk�r�ejRfe!jS_TnejRfejU_TeLejV_EeMejV_WdS )Ha<
pytest is a tool that eases test running and debugging.
To be able to use pytest, you should either write tests using
the logilab.common.testlib's framework or the unittest module of the
Python's standard library.
You can customize pytest's behaviour by defining a ``pytestconf.py`` file
somewhere in your test directory. In this file, you can add options or
change the way tests are run.
To add command line options, you must define a ``update_parser`` function in
your ``pytestconf.py`` file. The function must accept a single parameter
that will be the OptionParser's instance to customize.
If you wish to customize the tester, you'll have to define a class named
``CustomPyTester``. This class should extend the default `PyTester` class
defined in the pytest module. Take a look at the `PyTester` and `DjangoTester`
classes for more information about what can be done.
For instance, if you wish to add a custom -l option to specify a loglevel, you
could define the following ``pytestconf.py`` file ::
import logging
from logilab.common.pytest import PyTester
def update_parser(parser):
parser.add_option('-l', '--loglevel', dest='loglevel', action='store',
choices=('debug', 'info', 'warning', 'error', 'critical'),
default='critical', help="the default log level possible choices are "
"('debug', 'info', 'warning', 'error', 'critical')")
return parser
class CustomPyTester(PyTester):
def __init__(self, cvg, options):
super(CustomPyTester, self).__init__(cvg, options)
loglevel = options.loglevel.upper()
logger = logging.getLogger('erudi')
logger.setLevel(logging.getLevelName(loglevel))
In your TestCase class you can then get the value of a specific option with
the ``optval`` method::
class MyTestCase(TestCase):
def test_foo(self):
loglevel = self.optval('loglevel')
# ...
You can also tag your tag your test for fine filtering
With those tag::
from logilab.common.testlib import tag, TestCase
class Exemple(TestCase):
@tag('rouge', 'carre')
def toto(self):
pass
@tag('carre', 'vert')
def tata(self):
pass
@tag('rouge')
def titi(test):
pass
you can filter the function with a simple python expression
* ``toto`` and ``titi`` match ``rouge``
* ``toto``, ``tata`` and ``titi``, match ``rouge or carre``
* ``tata`` and ``titi`` match``rouge ^ carre``
* ``titi`` match ``rouge and not carre``
� )�print_functionzrestructuredtext ena\ %prog [OPTIONS] [testfile [testpattern]]
examples:
pytest path/to/mytests.py
pytest path/to/mytests.py TheseTests
pytest path/to/mytests.py TheseTests.test_thisone
pytest path/to/mytests.py -m '(not long and database) or regr'
pytest one (will run both test_thisone and test_thatone)
pytest path/to/mytests.py -s not (will skip test_notthisone)
Fz.pytest.restartN)�time�clock)�isgeneratorfunction�isclass)�contextmanager)�abspath_listdir)� textutils)�testlib�
STD_BLACKLIST)�unittest�start_interactive_mode)�
deprecated�__package__z7You have to install python-unittest2 to use this module)�modpath_from_file�load_module_from_modpathTz
pytestconf.pyc c sN t �� }t �| � z
dV W d|dk r>t|�s>t|d�r>|j}t �|� X dS )z<A context manager that temporary replaces the trace functionN�pytrace)�sys�gettrace�settrace�callable�hasattrr )�traceZoldtrace� r �F/opt/alt/python37/lib/python3.7/site-packages/logilab/common/pytest.py�
replace_trace� s
r c C s t � S )z3A context manager that temporary pauses any tracing)r r r r r �pause_trace� s r c @ s8 e Zd Zg Zeed�dd� ��Zeed�dd� ��ZdS )�TraceControllerz2[lgc 0.63.1] Use the pause_trace() context managerc C s | j �t� � | j d �� d S )N���)� ctx_stack�appendr � __enter__)�clsr r r �
pause_tracing� s zTraceController.pause_tracingc C s | j �� �d d d � d S )N)r �pop�__exit__)r"