XylotrechusZ
�
���g։ � �� � d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl Z
ddlmZ ddl
m
Z
ddl
mZ ddlmZ ddlmZ ddlmZ dd lmZ dd
lmZ ddlmZ ddlmZ dd
lmZ ddl m!Z! dZ" ejF e$� Z%dxa&xa'xa(xa)xa*a+ G d� de,� Z-d� Z. G d� d� Z/ G d� de� Z0d� Z1 G d� de� Z2d� Z3d� Z4 G d� de� Z5y# e$ r ddlmZ Y ��w xY w# e$ r ddl Z Y �w xY w)a�
Overview
========
The multiprocess plugin enables you to distribute your test run among a set of
worker processes that run tests in parallel. This can speed up CPU-bound test
runs (as long as the number of work processeses is around the number of
processors or cores available), but is mainly useful for IO-bound tests that
spend most of their time waiting for data to arrive from someplace else.
.. note ::
See :doc:`../doc_tests/test_multiprocess/multiprocess` for
additional documentation and examples. Use of this plugin on python
2.5 or earlier requires the multiprocessing_ module, also available
from PyPI.
.. _multiprocessing : http://code.google.com/p/python-multiprocessing/
How tests are distributed
=========================
The ideal case would be to dispatch each test to a worker process
separately. This ideal is not attainable in all cases, however, because many
test suites depend on context (class, module or package) fixtures.
The plugin can't know (unless you tell it -- see below!) if a context fixture
can be called many times concurrently (is re-entrant), or if it can be shared
among tests running in different processes. Therefore, if a context has
fixtures, the default behavior is to dispatch the entire suite to a worker as
a unit.
Controlling distribution
^^^^^^^^^^^^^^^^^^^^^^^^
There are two context-level variables that you can use to control this default
behavior.
If a context's fixtures are re-entrant, set ``_multiprocess_can_split_ = True``
in the context, and the plugin will dispatch tests in suites bound to that
context as if the context had no fixtures. This means that the fixtures will
execute concurrently and multiple times, typically once per test.
If a context's fixtures can be shared by tests running in different processes
-- such as a package-level fixture that starts an external http server or
initializes a shared database -- then set ``_multiprocess_shared_ = True`` in
the context. These fixtures will then execute in the primary nose process, and
tests in those contexts will be individually dispatched to run in parallel.
How results are collected and reported
======================================
As each test or suite executes in a worker process, results (failures, errors,
and specially handled exceptions like SkipTest) are collected in that
process. When the worker process finishes, it returns results to the main
nose process. There, any progress output is printed (dots!), and the
results from the test run are combined into a consolidated result
set. When results have been received for all dispatched tests, or all
workers have died, the result summary is output as normal.
Beware!
=======
Not all test suites will benefit from, or even operate correctly using, this
plugin. For example, CPU-bound tests will run more slowly if you don't have
multiple processors. There are also some differences in plugin
interactions and behaviors due to the way in which tests are dispatched and
loaded. In general, test loading under this plugin operates as if it were
always in directed mode instead of discovered mode. For instance, doctests
in test modules will always be found when using this plugin with the doctest
plugin.
But the biggest issue you will face is probably concurrency. Unless you
have kept your tests as religiously pure unit tests, with no side-effects, no
ordering issues, and no external dependencies, chances are you will experience
odd, intermittent and unexplainable failures and errors when using this
plugin. This doesn't necessarily mean the plugin is broken; it may mean that
your test suite is not safe for concurrency.
New Features in 1.1.0
=====================
* functions generated by test generators are now added to the worker queue
making them multi-threaded.
* fixed timeout functionality, now functions will be terminated with a
TimedOutException exception when they exceed their execution time. The
worker processes are not terminated.
* added ``--process-restartworker`` option to restart workers once they are
done, this helps control memory usage. Sometimes memory leaks can accumulate
making long runs very difficult.
* added global _instantiate_plugins to configure which plugins are started
on the worker processes.
� N)�TextTestRunner)�failure)�loader)�Plugin)�bytes_)�TextTestResult)�ContextSuite)�test_address)�_WritelnDecorator)�Empty)�warn)�StringIOc � � e Zd Zdd�Zd� Zy)�TimedOutExceptionc � � || _ y �N)�value)�selfr s �H/opt/hc_python/lib/python3.12/site-packages/nose/plugins/multiprocess.py�__init__zTimedOutException.__init__� s � ���
� c �, � t | j � S r )�reprr �r s r �__str__zTimedOutException.__str__� s � ��D�J�J��r N)z Timed Out)�__name__�
__module__�__qualname__r r � r r r r � s � �� r r c � � ddl m} ma t j t j t j
� } | � }t j t j |� |j |j |j |j |j f\ aaaa a
y # t $ r t dt � Y y w xY w)Nr )�Manager�ProcesszKmultiprocessing module is not available, multiprocess plugin cannot be used)�multiprocessingr! r"