Compare commits
60 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3bb1a8e467 | ||
|
|
9c8db61b6d | ||
|
|
fb6a6872a0 | ||
|
|
0987356f64 | ||
|
|
c31ec8b222 | ||
|
|
d0474076e9 | ||
|
|
02754d84d3 | ||
|
|
0738c3e1e2 | ||
|
|
15c51c497b | ||
|
|
0515f59c63 | ||
|
|
d5d630f1b7 | ||
|
|
e3eae96bb3 | ||
|
|
bc54b5b6b1 | ||
|
|
9884285915 | ||
|
|
d564364c44 | ||
|
|
435e5e8ac5 | ||
|
|
fbe793ed04 | ||
|
|
c454d410a1 | ||
|
|
f856cb74f4 | ||
|
|
5dc87143ad | ||
|
|
060e7b85ad | ||
|
|
1d631ca1cb | ||
|
|
d6139b2525 | ||
|
|
7f20416a70 | ||
|
|
5db31f1ee7 | ||
|
|
56d62c2d37 | ||
|
|
3f96e1b97f | ||
|
|
ad3e45590f | ||
|
|
2c66187dd8 | ||
|
|
6e99c0d4c5 | ||
|
|
a7f8c22ae5 | ||
|
|
43f7dbeb02 | ||
|
|
208f1f1f72 | ||
|
|
94fc4fbb85 | ||
|
|
b0916f06ce | ||
|
|
8356cfa39d | ||
|
|
f27265cd28 | ||
|
|
6b0a8c633b | ||
|
|
7f2ca0aecb | ||
|
|
64f8ad5469 | ||
|
|
144b37ae4b | ||
|
|
e41ba03edb | ||
|
|
cb3e734397 | ||
|
|
af8a5742ad | ||
|
|
d2d5ae9f5f | ||
|
|
05932011ed | ||
|
|
cd12d174c4 | ||
|
|
3652e21f3b | ||
|
|
a84b106a3b | ||
|
|
5d757f9db3 | ||
|
|
674c623ffa | ||
|
|
1fca8ee16d | ||
|
|
185595f596 | ||
|
|
55bc8c49d6 | ||
|
|
530c9b234a | ||
|
|
1ca9eff35d | ||
|
|
5320d25e47 | ||
|
|
96ad4d1cfd | ||
|
|
5c1a35fee4 | ||
|
|
665b8eda8d |
4
.github/PULL_REQUEST_TEMPLATE.md
vendored
4
.github/PULL_REQUEST_TEMPLATE.md
vendored
@@ -4,8 +4,8 @@ Here's a quick checklist that should be present in PRs:
|
|||||||
|
|
||||||
- [ ] Make sure to include reasonable tests for your change if necessary
|
- [ ] Make sure to include reasonable tests for your change if necessary
|
||||||
|
|
||||||
- [ ] Add a *news* file into the `changelog` folder, following these guidelines:
|
- [ ] We use [towncrier](https://pypi.python.org/pypi/towncrier) for changelog management, so please add a *news* file into the `changelog` folder following these guidelines:
|
||||||
* Name it `$issue_id.$type` for example `588.bug`
|
* Name it `$issue_id.$type` for example `588.bugfix`;
|
||||||
* If you don't have an issue_id change it to the PR id after creating it
|
* If you don't have an issue_id change it to the PR id after creating it
|
||||||
* Ensure type is one of `removal`, `feature`, `bugfix`, `vendor`, `doc` or `trivial`
|
* Ensure type is one of `removal`, `feature`, `bugfix`, `vendor`, `doc` or `trivial`
|
||||||
* Make sure to use full sentences with correct case and punctuation, for example:
|
* Make sure to use full sentences with correct case and punctuation, for example:
|
||||||
|
|||||||
10
.travis.yml
10
.travis.yml
@@ -6,13 +6,17 @@ python:
|
|||||||
- '3.4'
|
- '3.4'
|
||||||
- '3.5'
|
- '3.5'
|
||||||
- '3.6'
|
- '3.6'
|
||||||
install: pip install tox-travis setuptools_scm
|
env:
|
||||||
|
- TOXENV=py-pytest30
|
||||||
|
- TOXENV=py-pytest31
|
||||||
|
- TOXENV=py-pytest32
|
||||||
|
install: pip install tox setuptools_scm
|
||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
# note: please use "tox --listenvs" to populate the build matrix
|
# note: please use "tox --listenvs" to populate the build matrix
|
||||||
- python: "3.5"
|
- python: "3.6"
|
||||||
env: TOXENV=flakes
|
env: TOXENV=flakes
|
||||||
- python: "3.5"
|
- python: "3.6"
|
||||||
env: TOXENV=readme
|
env: TOXENV=readme
|
||||||
|
|
||||||
script: tox
|
script: tox
|
||||||
|
|||||||
@@ -1,6 +1,67 @@
|
|||||||
|
pytest-xdist 1.19.0 (2017-08-09)
|
||||||
|
================================
|
||||||
|
|
||||||
|
Deprecations and Removals
|
||||||
|
-------------------------
|
||||||
|
|
||||||
|
- ``--boxed`` functionality has been moved to a separate plugin, `pytest-forked
|
||||||
|
<https://github.com/pytest-dev/pytest-forked>`_. This release now depends on
|
||||||
|
`` pytest-forked`` and provides ``--boxed`` as a backward compatibility
|
||||||
|
option. (`#1 <https://github.com/pytest-dev/pytest-xdist/issues/1>`_)
|
||||||
|
|
||||||
|
|
||||||
|
Features
|
||||||
|
--------
|
||||||
|
|
||||||
|
- New ``--dist=loadscope`` option: sends group of related tests to the same
|
||||||
|
worker. Tests are grouped by module for test functions and by class for test
|
||||||
|
methods. See ``README.rst`` for more information. (`#191 <https://github.com
|
||||||
|
/pytest-dev/pytest-xdist/issues/191>`_)
|
||||||
|
|
||||||
|
- Warnings are now properly transferred from workers to the master node. (`#92
|
||||||
|
<https://github.com/pytest-dev/pytest-xdist/issues/92>`_)
|
||||||
|
|
||||||
|
|
||||||
|
Bug Fixes
|
||||||
|
---------
|
||||||
|
|
||||||
|
- Fix serialization of native tracebacks (``--tb=native``). (`#196
|
||||||
|
<https://github.com/pytest-dev/pytest-xdist/issues/196>`_)
|
||||||
|
|
||||||
|
|
||||||
|
pytest-xdist 1.18.2 (2017-07-28)
|
||||||
|
================================
|
||||||
|
|
||||||
|
Bug Fixes
|
||||||
|
---------
|
||||||
|
|
||||||
|
- Removal of unnecessary dependency on incorrect version of py. (`#105
|
||||||
|
<https://github.com/pytest-dev/pytest-xdist/issues/105>`_)
|
||||||
|
|
||||||
|
- Fix bug in internal event-loop error handler in the master node. This bug
|
||||||
|
would shadow the original errors making extremely hard/impossible for users
|
||||||
|
to diagnose the problem properly. (`#175 <https://github.com/pytest-
|
||||||
|
dev/pytest-xdist/issues/175>`_)
|
||||||
|
|
||||||
|
|
||||||
|
pytest-xdist 1.18.1 (2017-07-05)
|
||||||
|
================================
|
||||||
|
|
||||||
|
Bug Fixes
|
||||||
|
---------
|
||||||
|
|
||||||
|
- Fixed serialization of ``longrepr.sections`` during error reporting from
|
||||||
|
workers. (`#171 <https://github.com/pytest-dev/pytest-xdist/issues/171>`_)
|
||||||
|
|
||||||
|
- Fix ``ReprLocal`` not being unserialized breaking --showlocals usages. (`#176
|
||||||
|
<https://github.com/pytest-dev/pytest-xdist/issues/176>`_)
|
||||||
|
|
||||||
|
|
||||||
pytest-xdist 1.18.0 (2017-06-26)
|
pytest-xdist 1.18.0 (2017-06-26)
|
||||||
================================
|
================================
|
||||||
|
|
||||||
|
- ``pytest-xdist`` now requires ``pytest>=3.0.0``.
|
||||||
|
|
||||||
Features
|
Features
|
||||||
--------
|
--------
|
||||||
|
|
||||||
|
|||||||
92
README.rst
92
README.rst
@@ -22,8 +22,6 @@ test execution modes:
|
|||||||
those for a combined test run. This allows to speed up
|
those for a combined test run. This allows to speed up
|
||||||
development or to use special resources of `remote machines`_.
|
development or to use special resources of `remote machines`_.
|
||||||
|
|
||||||
* ``--boxed``: (not available on Windows) run each test in a boxed_
|
|
||||||
subprocess to survive ``SEGFAULTS`` or otherwise dying processes
|
|
||||||
|
|
||||||
* ``--looponfail``: run your tests repeatedly in a subprocess. After each run
|
* ``--looponfail``: run your tests repeatedly in a subprocess. After each run
|
||||||
py.test waits until a file in your project changes and then re-runs
|
py.test waits until a file in your project changes and then re-runs
|
||||||
@@ -44,10 +42,6 @@ Installation
|
|||||||
|
|
||||||
Install the plugin with::
|
Install the plugin with::
|
||||||
|
|
||||||
easy_install pytest-xdist
|
|
||||||
|
|
||||||
# or
|
|
||||||
|
|
||||||
pip install pytest-xdist
|
pip install pytest-xdist
|
||||||
|
|
||||||
or use the package in develop/in-place mode with
|
or use the package in develop/in-place mode with
|
||||||
@@ -192,6 +186,7 @@ at once. The specifications strings use the `xspec syntax`_.
|
|||||||
Identifying the worker process during a test
|
Identifying the worker process during a test
|
||||||
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
|
||||||
|
*New in version 1.15.*
|
||||||
|
|
||||||
If you need to determine the identity of a worker process in
|
If you need to determine the identity of a worker process in
|
||||||
a test or fixture, you may use the ``worker_id`` fixture to do so:
|
a test or fixture, you may use the ``worker_id`` fixture to do so:
|
||||||
@@ -217,8 +212,6 @@ The information about the worker_id in a test is stored in the TestReport as
|
|||||||
well, under worker_id attribute.
|
well, under worker_id attribute.
|
||||||
|
|
||||||
|
|
||||||
*New in version 1.15.*
|
|
||||||
|
|
||||||
Specifying test exec environments in an ini file
|
Specifying test exec environments in an ini file
|
||||||
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
|
||||||
@@ -244,6 +237,83 @@ and then just type::
|
|||||||
|
|
||||||
to run tests in each of the environments.
|
to run tests in each of the environments.
|
||||||
|
|
||||||
|
|
||||||
|
Sending groups of related tests to the same worker
|
||||||
|
++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
|
||||||
|
*New in version 1.19.*
|
||||||
|
|
||||||
|
.. note::
|
||||||
|
This is an **experimental** feature: the actual functionality will
|
||||||
|
likely stay the same, but the CLI might change slightly in future versions.
|
||||||
|
|
||||||
|
You can send groups of related tests to the same worker by using the
|
||||||
|
``--dist=loadscope`` option. Tests will be grouped by **module**
|
||||||
|
for *test functions* and by **class** for *test methods*.
|
||||||
|
|
||||||
|
For example, consider this two test files:
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
# content of test_container.py
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
def test_container_startup():
|
||||||
|
pass
|
||||||
|
|
||||||
|
def test_container_logging():
|
||||||
|
pass
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('methods', ['ssh', 'http'])
|
||||||
|
def test_container_communication(methods):
|
||||||
|
pass
|
||||||
|
|
||||||
|
# content of test_io.py
|
||||||
|
class TestHDF:
|
||||||
|
|
||||||
|
def test_listing(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def test_search(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class TestXML:
|
||||||
|
|
||||||
|
def test_listing(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def test_search(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
By executing ``pytest -v --dist=loadscope -n4`` you might get this output
|
||||||
|
(sorted by worker for readability)::
|
||||||
|
|
||||||
|
============================= test session starts =============================
|
||||||
|
<skip header>
|
||||||
|
gw0 [8] / gw1 [8] / gw2 [8] / gw3 [8]
|
||||||
|
scheduling tests via LoadScopeScheduling
|
||||||
|
|
||||||
|
[gw0] PASSED test_container.py::test_container_communication[http]
|
||||||
|
[gw0] PASSED test_container.py::test_container_communication[ssh]
|
||||||
|
[gw0] PASSED test_container.py::test_container_logging
|
||||||
|
[gw0] PASSED test_container.py::test_container_startup
|
||||||
|
[gw1] PASSED test_io.py::TestHDF::test_listing
|
||||||
|
[gw1] PASSED test_io.py::TestHDF::test_search
|
||||||
|
[gw2] PASSED test_io.py::TestXML::test_listing
|
||||||
|
[gw2] PASSED test_io.py::TestXML::test_search
|
||||||
|
|
||||||
|
========================== 8 passed in 0.56 seconds ===========================
|
||||||
|
|
||||||
|
As you can see, all test functions from ``test_container.py`` executed on
|
||||||
|
the same worker ``gw0``, while the test methods from classes ``TestHDF`` and
|
||||||
|
``TestXML`` executed in workers ``gw1`` and ``gw2`` respectively.
|
||||||
|
|
||||||
|
Currently the groupings can't be customized, with grouping by class takes
|
||||||
|
priority over grouping by module.
|
||||||
|
|
||||||
|
|
||||||
Specifying "rsync" dirs in an ini-file
|
Specifying "rsync" dirs in an ini-file
|
||||||
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
|
||||||
@@ -262,9 +332,3 @@ where the configuration file was found.
|
|||||||
.. _`pytest-xdist`: http://pypi.python.org/pypi/pytest-xdist
|
.. _`pytest-xdist`: http://pypi.python.org/pypi/pytest-xdist
|
||||||
.. _`pytest-xdist repository`: https://github.com/pytest-dev/pytest-xdist
|
.. _`pytest-xdist repository`: https://github.com/pytest-dev/pytest-xdist
|
||||||
.. _`pytest`: http://pytest.org
|
.. _`pytest`: http://pytest.org
|
||||||
|
|
||||||
Issue and Bug Tracker
|
|
||||||
------------------------
|
|
||||||
|
|
||||||
Please use the `pytest issue tracker <https://github.com/pytest-dev/pytest/issues>`_
|
|
||||||
for reporting bugs in this plugin.
|
|
||||||
|
|||||||
@@ -6,14 +6,14 @@
|
|||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if sections[section] %}
|
{% if sections[section] %}
|
||||||
{% for category, val in definitions.items() if category in sections[section] and category != 'trivial' %}
|
{% for category, val in definitions.items() if category in sections[section] %}
|
||||||
|
|
||||||
{{ definitions[category]['name'] }}
|
{{ definitions[category]['name'] }}
|
||||||
{{ underline * definitions[category]['name']|length }}
|
{{ underline * definitions[category]['name']|length }}
|
||||||
|
|
||||||
{% if definitions[category]['showcontent'] %}
|
{% if definitions[category]['showcontent'] %}
|
||||||
{% for text, values in sections[section][category]|dictsort(by='value') %}
|
{% for text, values in sections[section][category]|dictsort(by='value') %}
|
||||||
- {{ text }}{% if category != 'vendor' %} ({{ values|sort|join(', ') }}){% endif %}
|
- {{ text }}{% if category != 'vendor' %} (`{{ values[0] }} <https://github.com/pytest-dev/pytest-xdist/issues/{{ values[0][1:] }}>`_){% endif %}
|
||||||
|
|
||||||
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
.. note::
|
||||||
|
|
||||||
|
Since 1.19.0, the actual implementation of the ``--boxed`` option has been moved to a
|
||||||
|
separate plugin, `pytest-forked <https://github.com/pytest-dev/pytest-forked>`_
|
||||||
|
which can be installed independently. The ``--boxed`` command-line options remains
|
||||||
|
for backward compatibility reasons.
|
||||||
|
|
||||||
|
|
||||||
If your testing involves C or C++ libraries you might have to deal
|
If your testing involves C or C++ libraries you might have to deal
|
||||||
@@ -19,7 +25,7 @@ to run each test in a controlled subprocess. Here is a basic example::
|
|||||||
|
|
||||||
If you run this with::
|
If you run this with::
|
||||||
|
|
||||||
$ py.test --boxed
|
$ py.test -n1
|
||||||
=========================== test session starts ============================
|
=========================== test session starts ============================
|
||||||
platform linux2 -- Python 2.7.3 -- pytest-2.3.0.dev8
|
platform linux2 -- Python 2.7.3 -- pytest-2.3.0.dev8
|
||||||
plugins: xdist, bugzilla, cache, oejskit, cli, pep8, cov
|
plugins: xdist, bugzilla, cache, oejskit, cli, pep8, cov
|
||||||
@@ -40,7 +46,7 @@ You'll see that a couple of tests are reported as crashing, indicated
|
|||||||
by lower-case ``f`` and the respective failure summary. You can also use
|
by lower-case ``f`` and the respective failure summary. You can also use
|
||||||
the xdist-provided parallelization feature to speed up your testing::
|
the xdist-provided parallelization feature to speed up your testing::
|
||||||
|
|
||||||
$ py.test --boxed -n3
|
$ py.test -n3
|
||||||
=========================== test session starts ============================
|
=========================== test session starts ============================
|
||||||
platform linux2 -- Python 2.7.3 -- pytest-2.3.0.dev8
|
platform linux2 -- Python 2.7.3 -- pytest-2.3.0.dev8
|
||||||
plugins: xdist, bugzilla, cache, oejskit, cli, pep8, cov
|
plugins: xdist, bugzilla, cache, oejskit, cli, pep8, cov
|
||||||
|
|||||||
37
example/loadscope/epsilon/__init__.py
Normal file
37
example/loadscope/epsilon/__init__.py
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
def epsilon1(arg1, arg2=1000):
|
||||||
|
"""Do epsilon1
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
|
||||||
|
>>> epsilon1(10, 20)
|
||||||
|
40
|
||||||
|
>>> epsilon1(30)
|
||||||
|
1040
|
||||||
|
"""
|
||||||
|
return arg1 + arg2 + 10
|
||||||
|
|
||||||
|
|
||||||
|
def epsilon2(arg1, arg2=1000):
|
||||||
|
"""Do epsilon2
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
|
||||||
|
>>> epsilon2(10, 20)
|
||||||
|
-20
|
||||||
|
>>> epsilon2(30)
|
||||||
|
-980
|
||||||
|
"""
|
||||||
|
return arg1 - arg2 - 10
|
||||||
|
|
||||||
|
|
||||||
|
def epsilon3(arg1, arg2=1000):
|
||||||
|
"""Do epsilon3
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
|
||||||
|
>>> epsilon3(10, 20)
|
||||||
|
200
|
||||||
|
>>> epsilon3(30)
|
||||||
|
30000
|
||||||
|
"""
|
||||||
|
return arg1 * arg2
|
||||||
3
example/loadscope/requirements.txt
Normal file
3
example/loadscope/requirements.txt
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
ipdb
|
||||||
|
pytest
|
||||||
|
../../
|
||||||
51
example/loadscope/test/test_alpha.py
Normal file
51
example/loadscope/test/test_alpha.py
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
from time import sleep
|
||||||
|
|
||||||
|
|
||||||
|
def test_alpha0():
|
||||||
|
sleep(5)
|
||||||
|
assert True
|
||||||
|
|
||||||
|
|
||||||
|
def test_alpha1():
|
||||||
|
sleep(5)
|
||||||
|
assert True
|
||||||
|
|
||||||
|
|
||||||
|
def test_alpha2():
|
||||||
|
sleep(5)
|
||||||
|
assert True
|
||||||
|
|
||||||
|
|
||||||
|
def test_alpha3():
|
||||||
|
sleep(5)
|
||||||
|
assert True
|
||||||
|
|
||||||
|
|
||||||
|
def test_alpha4():
|
||||||
|
sleep(5)
|
||||||
|
assert True
|
||||||
|
|
||||||
|
|
||||||
|
def test_alpha5():
|
||||||
|
sleep(5)
|
||||||
|
assert True
|
||||||
|
|
||||||
|
|
||||||
|
def test_alpha6():
|
||||||
|
sleep(5)
|
||||||
|
assert True
|
||||||
|
|
||||||
|
|
||||||
|
def test_alpha7():
|
||||||
|
sleep(5)
|
||||||
|
assert True
|
||||||
|
|
||||||
|
|
||||||
|
def test_alpha8():
|
||||||
|
sleep(5)
|
||||||
|
assert True
|
||||||
|
|
||||||
|
|
||||||
|
def test_alpha9():
|
||||||
|
sleep(5)
|
||||||
|
assert True
|
||||||
51
example/loadscope/test/test_beta.py
Normal file
51
example/loadscope/test/test_beta.py
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
from time import sleep
|
||||||
|
|
||||||
|
|
||||||
|
def test_beta0():
|
||||||
|
sleep(5)
|
||||||
|
assert True
|
||||||
|
|
||||||
|
|
||||||
|
def test_beta1():
|
||||||
|
sleep(5)
|
||||||
|
assert True
|
||||||
|
|
||||||
|
|
||||||
|
def test_beta2():
|
||||||
|
sleep(5)
|
||||||
|
assert True
|
||||||
|
|
||||||
|
|
||||||
|
def test_beta3():
|
||||||
|
sleep(5)
|
||||||
|
assert True
|
||||||
|
|
||||||
|
|
||||||
|
def test_beta4():
|
||||||
|
sleep(5)
|
||||||
|
assert True
|
||||||
|
|
||||||
|
|
||||||
|
def test_beta5():
|
||||||
|
sleep(5)
|
||||||
|
assert True
|
||||||
|
|
||||||
|
|
||||||
|
def test_beta6():
|
||||||
|
sleep(5)
|
||||||
|
assert True
|
||||||
|
|
||||||
|
|
||||||
|
def test_beta7():
|
||||||
|
sleep(5)
|
||||||
|
assert True
|
||||||
|
|
||||||
|
|
||||||
|
def test_beta8():
|
||||||
|
sleep(5)
|
||||||
|
assert True
|
||||||
|
|
||||||
|
|
||||||
|
def test_beta9():
|
||||||
|
sleep(5)
|
||||||
|
assert True
|
||||||
88
example/loadscope/test/test_delta.py
Normal file
88
example/loadscope/test/test_delta.py
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
from time import sleep
|
||||||
|
from unittest import TestCase
|
||||||
|
|
||||||
|
|
||||||
|
class Delta1(TestCase):
|
||||||
|
|
||||||
|
def test_delta0(self):
|
||||||
|
sleep(5)
|
||||||
|
assert True
|
||||||
|
|
||||||
|
def test_delta1(self):
|
||||||
|
sleep(5)
|
||||||
|
assert True
|
||||||
|
|
||||||
|
def test_delta2(self):
|
||||||
|
sleep(5)
|
||||||
|
assert True
|
||||||
|
|
||||||
|
def test_delta3(self):
|
||||||
|
sleep(5)
|
||||||
|
assert True
|
||||||
|
|
||||||
|
def test_delta4(self):
|
||||||
|
sleep(5)
|
||||||
|
assert True
|
||||||
|
|
||||||
|
def test_delta5(self):
|
||||||
|
sleep(5)
|
||||||
|
assert True
|
||||||
|
|
||||||
|
def test_delta6(self):
|
||||||
|
sleep(5)
|
||||||
|
assert True
|
||||||
|
|
||||||
|
def test_delta7(self):
|
||||||
|
sleep(5)
|
||||||
|
assert True
|
||||||
|
|
||||||
|
def test_delta8(self):
|
||||||
|
sleep(5)
|
||||||
|
assert True
|
||||||
|
|
||||||
|
def test_delta9(self):
|
||||||
|
sleep(5)
|
||||||
|
assert True
|
||||||
|
|
||||||
|
|
||||||
|
class Delta2(TestCase):
|
||||||
|
|
||||||
|
def test_delta0(self):
|
||||||
|
sleep(5)
|
||||||
|
assert True
|
||||||
|
|
||||||
|
def test_delta1(self):
|
||||||
|
sleep(5)
|
||||||
|
assert True
|
||||||
|
|
||||||
|
def test_delta2(self):
|
||||||
|
sleep(5)
|
||||||
|
assert True
|
||||||
|
|
||||||
|
def test_delta3(self):
|
||||||
|
sleep(5)
|
||||||
|
assert True
|
||||||
|
|
||||||
|
def test_delta4(self):
|
||||||
|
sleep(5)
|
||||||
|
assert True
|
||||||
|
|
||||||
|
def test_delta5(self):
|
||||||
|
sleep(5)
|
||||||
|
assert True
|
||||||
|
|
||||||
|
def test_delta6(self):
|
||||||
|
sleep(5)
|
||||||
|
assert True
|
||||||
|
|
||||||
|
def test_delta7(self):
|
||||||
|
sleep(5)
|
||||||
|
assert True
|
||||||
|
|
||||||
|
def test_delta8(self):
|
||||||
|
sleep(5)
|
||||||
|
assert True
|
||||||
|
|
||||||
|
def test_delta9(self):
|
||||||
|
sleep(5)
|
||||||
|
assert True
|
||||||
51
example/loadscope/test/test_gamma.py
Normal file
51
example/loadscope/test/test_gamma.py
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
from time import sleep
|
||||||
|
|
||||||
|
|
||||||
|
def test_gamma0():
|
||||||
|
sleep(5)
|
||||||
|
assert True
|
||||||
|
|
||||||
|
|
||||||
|
def test_gamma1():
|
||||||
|
sleep(5)
|
||||||
|
assert True
|
||||||
|
|
||||||
|
|
||||||
|
def test_gamma2():
|
||||||
|
sleep(5)
|
||||||
|
assert True
|
||||||
|
|
||||||
|
|
||||||
|
def test_gamma3():
|
||||||
|
sleep(5)
|
||||||
|
assert True
|
||||||
|
|
||||||
|
|
||||||
|
def test_gamma4():
|
||||||
|
sleep(5)
|
||||||
|
assert True
|
||||||
|
|
||||||
|
|
||||||
|
def test_gamma5():
|
||||||
|
sleep(5)
|
||||||
|
assert True
|
||||||
|
|
||||||
|
|
||||||
|
def test_gamma6():
|
||||||
|
sleep(5)
|
||||||
|
assert True
|
||||||
|
|
||||||
|
|
||||||
|
def test_gamma7():
|
||||||
|
sleep(5)
|
||||||
|
assert True
|
||||||
|
|
||||||
|
|
||||||
|
def test_gamma8():
|
||||||
|
sleep(5)
|
||||||
|
assert True
|
||||||
|
|
||||||
|
|
||||||
|
def test_gamma9():
|
||||||
|
sleep(5)
|
||||||
|
assert True
|
||||||
17
example/loadscope/tox.ini
Normal file
17
example/loadscope/tox.ini
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
[tox]
|
||||||
|
envlist = test
|
||||||
|
setupdir = {toxinidir}/../../
|
||||||
|
|
||||||
|
[testenv:test]
|
||||||
|
basepython = python3
|
||||||
|
passenv = http_proxy https_proxy
|
||||||
|
deps = -rrequirements.txt
|
||||||
|
changedir = {envtmpdir}
|
||||||
|
commands =
|
||||||
|
py.test -s -v \
|
||||||
|
--doctest-modules \
|
||||||
|
--junitxml=tests.xml \
|
||||||
|
--dist=loadscope \
|
||||||
|
--tx=8*popen \
|
||||||
|
{toxinidir}/test \
|
||||||
|
{toxinidir}/epsilon
|
||||||
@@ -3,3 +3,6 @@ universal = 1
|
|||||||
|
|
||||||
[metadata]
|
[metadata]
|
||||||
license_file = LICENSE
|
license_file = LICENSE
|
||||||
|
|
||||||
|
[flake8]
|
||||||
|
max-line-length = 100
|
||||||
|
|||||||
15
setup.py
15
setup.py
@@ -1,4 +1,12 @@
|
|||||||
from setuptools import setup
|
from sys import version_info
|
||||||
|
|
||||||
|
from setuptools import setup, find_packages
|
||||||
|
|
||||||
|
install_requires = ['execnet>=1.1', 'pytest>=3.0.0', 'pytest-forked']
|
||||||
|
|
||||||
|
if version_info < (2, 7):
|
||||||
|
install_requires.append('ordereddict')
|
||||||
|
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="pytest-xdist",
|
name="pytest-xdist",
|
||||||
@@ -11,16 +19,15 @@ setup(
|
|||||||
author_email='pytest-dev@python.org,holger@merlinux.eu',
|
author_email='pytest-dev@python.org,holger@merlinux.eu',
|
||||||
url='https://github.com/pytest-dev/pytest-xdist',
|
url='https://github.com/pytest-dev/pytest-xdist',
|
||||||
platforms=['linux', 'osx', 'win32'],
|
platforms=['linux', 'osx', 'win32'],
|
||||||
packages=['xdist'],
|
packages=find_packages(exclude=['testing', 'example']),
|
||||||
entry_points={
|
entry_points={
|
||||||
'pytest11': [
|
'pytest11': [
|
||||||
'xdist = xdist.plugin',
|
'xdist = xdist.plugin',
|
||||||
'xdist.looponfail = xdist.looponfail',
|
'xdist.looponfail = xdist.looponfail',
|
||||||
'xdist.boxed = xdist.boxed',
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
zip_safe=False,
|
zip_safe=False,
|
||||||
install_requires=['execnet>=1.1', 'pytest>=3.0.0', 'py>=1.4.22'],
|
install_requires=install_requires,
|
||||||
setup_requires=['setuptools_scm'],
|
setup_requires=['setuptools_scm'],
|
||||||
classifiers=[
|
classifiers=[
|
||||||
'Development Status :: 5 - Production/Stable',
|
'Development Status :: 5 - Production/Stable',
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import re
|
||||||
|
|
||||||
import py
|
import py
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@@ -337,6 +339,21 @@ class TestTerminalReporting:
|
|||||||
"E assert 0",
|
"E assert 0",
|
||||||
])
|
])
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('n', ['-n0', '-n1'])
|
||||||
|
def test_logwarning(self, testdir, n):
|
||||||
|
from pkg_resources import parse_version
|
||||||
|
if parse_version(pytest.__version__) < parse_version('3.1'):
|
||||||
|
pytest.skip('pytest warnings requires >= 3.1')
|
||||||
|
testdir.makepyfile("""
|
||||||
|
import warnings
|
||||||
|
def test_func():
|
||||||
|
warnings.warn('this is a warning')
|
||||||
|
""")
|
||||||
|
result = testdir.runpytest(n)
|
||||||
|
result.stdout.fnmatch_lines([
|
||||||
|
"*this is a warning*",
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
def test_teardownfails_one_function(testdir):
|
def test_teardownfails_one_function(testdir):
|
||||||
p = testdir.makepyfile("""
|
p = testdir.makepyfile("""
|
||||||
@@ -669,6 +686,20 @@ def test_worker_id_fixture(testdir, n):
|
|||||||
assert worker_ids == set(['gw0', 'gw1'])
|
assert worker_ids == set(['gw0', 'gw1'])
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('tb',
|
||||||
|
['auto', 'long', 'short', 'no', 'line', 'native'])
|
||||||
|
def test_error_report_styles(testdir, tb):
|
||||||
|
testdir.makepyfile("""
|
||||||
|
import pytest
|
||||||
|
def test_error_report_styles():
|
||||||
|
raise RuntimeError('some failure happened')
|
||||||
|
""")
|
||||||
|
result = testdir.runpytest('-n1', '--tb=%s' % tb)
|
||||||
|
if tb != 'no':
|
||||||
|
result.stdout.fnmatch_lines('*some failure happened*')
|
||||||
|
result.assert_outcomes(failed=1)
|
||||||
|
|
||||||
|
|
||||||
def test_color_yes_collection_on_non_atty(testdir, request):
|
def test_color_yes_collection_on_non_atty(testdir, request):
|
||||||
"""skip collect progress report when working on non-terminals.
|
"""skip collect progress report when working on non-terminals.
|
||||||
|
|
||||||
@@ -710,3 +741,62 @@ def test_internal_error_with_maxfail(testdir):
|
|||||||
result = testdir.runpytest_subprocess('--maxfail=1', '-n1')
|
result = testdir.runpytest_subprocess('--maxfail=1', '-n1')
|
||||||
result.stdout.fnmatch_lines(['* 1 error in *'])
|
result.stdout.fnmatch_lines(['* 1 error in *'])
|
||||||
assert 'INTERNALERROR' not in result.stderr.str()
|
assert 'INTERNALERROR' not in result.stderr.str()
|
||||||
|
|
||||||
|
|
||||||
|
class TestLoadScope:
|
||||||
|
|
||||||
|
def test_by_module(self, testdir):
|
||||||
|
test_file = """
|
||||||
|
import pytest
|
||||||
|
@pytest.mark.parametrize('i', range(10))
|
||||||
|
def test(i):
|
||||||
|
pass
|
||||||
|
"""
|
||||||
|
testdir.makepyfile(
|
||||||
|
test_a=test_file,
|
||||||
|
test_b=test_file,
|
||||||
|
)
|
||||||
|
result = testdir.runpytest('-n2', '--dist=loadscope', '-v')
|
||||||
|
assert get_workers_and_test_count_by_prefix(
|
||||||
|
'test_a.py::test', result.outlines) in ({'gw0': 10}, {'gw1': 10})
|
||||||
|
assert get_workers_and_test_count_by_prefix(
|
||||||
|
'test_b.py::test', result.outlines) in ({'gw0': 10}, {'gw1': 10})
|
||||||
|
|
||||||
|
def test_by_class(self, testdir):
|
||||||
|
testdir.makepyfile(test_a="""
|
||||||
|
import pytest
|
||||||
|
class TestA:
|
||||||
|
@pytest.mark.parametrize('i', range(10))
|
||||||
|
def test(self, i):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class TestB:
|
||||||
|
@pytest.mark.parametrize('i', range(10))
|
||||||
|
def test(self, i):
|
||||||
|
pass
|
||||||
|
""")
|
||||||
|
result = testdir.runpytest('-n2', '--dist=loadscope', '-v')
|
||||||
|
assert get_workers_and_test_count_by_prefix(
|
||||||
|
'test_a.py::TestA', result.outlines) in ({'gw0': 10}, {'gw1': 10})
|
||||||
|
assert get_workers_and_test_count_by_prefix(
|
||||||
|
'test_a.py::TestB', result.outlines) in ({'gw0': 10}, {'gw1': 10})
|
||||||
|
|
||||||
|
|
||||||
|
def parse_tests_and_workers_from_output(lines):
|
||||||
|
result = []
|
||||||
|
for line in lines:
|
||||||
|
# example match: "[gw0] PASSED test_a.py::test[7]"
|
||||||
|
m = re.match(r'\[(gw\d)\]\s(.*?)\s(.*::.*)', line.strip())
|
||||||
|
if m:
|
||||||
|
worker, status, nodeid = m.groups()
|
||||||
|
result.append((worker, status, nodeid))
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def get_workers_and_test_count_by_prefix(prefix, lines,
|
||||||
|
expected_status='PASSED'):
|
||||||
|
result = {}
|
||||||
|
for worker, status, nodeid in parse_tests_and_workers_from_output(lines):
|
||||||
|
if expected_status == status and nodeid.startswith(prefix):
|
||||||
|
result[worker] = result.get(worker, 0) + 1
|
||||||
|
return result
|
||||||
|
|||||||
@@ -1,58 +0,0 @@
|
|||||||
import pytest
|
|
||||||
import os
|
|
||||||
|
|
||||||
needsfork = pytest.mark.skipif(not hasattr(os, "fork"),
|
|
||||||
reason="os.fork required")
|
|
||||||
|
|
||||||
|
|
||||||
@needsfork
|
|
||||||
def test_functional_boxed(testdir):
|
|
||||||
p1 = testdir.makepyfile("""
|
|
||||||
import os
|
|
||||||
def test_function():
|
|
||||||
os.kill(os.getpid(), 15)
|
|
||||||
""")
|
|
||||||
result = testdir.runpytest(p1, "--boxed")
|
|
||||||
result.stdout.fnmatch_lines([
|
|
||||||
"*CRASHED*",
|
|
||||||
"*1 failed*"
|
|
||||||
])
|
|
||||||
|
|
||||||
|
|
||||||
@needsfork
|
|
||||||
@pytest.mark.parametrize("capmode", [
|
|
||||||
"no",
|
|
||||||
pytest.mark.xfail("sys", reason="capture cleanup needed"),
|
|
||||||
pytest.mark.xfail("fd", reason="capture cleanup needed")])
|
|
||||||
def test_functional_boxed_capturing(testdir, capmode):
|
|
||||||
p1 = testdir.makepyfile("""
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
def test_function():
|
|
||||||
sys.stdout.write("hello\\n")
|
|
||||||
sys.stderr.write("world\\n")
|
|
||||||
os.kill(os.getpid(), 15)
|
|
||||||
""")
|
|
||||||
result = testdir.runpytest(p1, "--boxed", "--capture=%s" % capmode)
|
|
||||||
result.stdout.fnmatch_lines("""
|
|
||||||
*CRASHED*
|
|
||||||
*stdout*
|
|
||||||
hello
|
|
||||||
*stderr*
|
|
||||||
world
|
|
||||||
*1 failed*
|
|
||||||
""")
|
|
||||||
|
|
||||||
|
|
||||||
class TestOptionEffects:
|
|
||||||
def test_boxed_option_default(self, testdir):
|
|
||||||
tmpdir = testdir.tmpdir.ensure("subdir", dir=1)
|
|
||||||
config = testdir.parseconfig()
|
|
||||||
assert not config.option.boxed
|
|
||||||
pytest.importorskip("execnet")
|
|
||||||
config = testdir.parseconfig('-d', tmpdir)
|
|
||||||
assert not config.option.boxed
|
|
||||||
|
|
||||||
def test_is_not_boxed_by_default(self, testdir):
|
|
||||||
config = testdir.parseconfig(testdir.tmpdir)
|
|
||||||
assert not config.option.boxed
|
|
||||||
@@ -1,6 +1,10 @@
|
|||||||
from xdist.dsession import (
|
from xdist.dsession import DSession
|
||||||
DSession, LoadScheduling, EachScheduling, report_collection_diff,
|
from xdist.report import report_collection_diff
|
||||||
|
from xdist.scheduler import (
|
||||||
|
EachScheduling,
|
||||||
|
LoadScheduling,
|
||||||
)
|
)
|
||||||
|
|
||||||
import py
|
import py
|
||||||
import pytest
|
import pytest
|
||||||
import execnet
|
import execnet
|
||||||
|
|||||||
@@ -193,6 +193,8 @@ class TestLooponFailing:
|
|||||||
assert 'test_one' not in remotecontrol.failures[0]
|
assert 'test_one' not in remotecontrol.failures[0]
|
||||||
assert 'test_two' in remotecontrol.failures[0]
|
assert 'test_two' in remotecontrol.failures[0]
|
||||||
|
|
||||||
|
@py.test.mark.xfail(py.test.__version__ >= "3.1",
|
||||||
|
reason="broken by pytest 3.1+")
|
||||||
def test_looponfail_removed_test(self, testdir):
|
def test_looponfail_removed_test(self, testdir):
|
||||||
modcol = testdir.getmodulecol("""
|
modcol = testdir.getmodulecol("""
|
||||||
def test_one():
|
def test_one():
|
||||||
|
|||||||
@@ -29,9 +29,9 @@ class EventCall:
|
|||||||
class SlaveSetup:
|
class SlaveSetup:
|
||||||
use_callback = False
|
use_callback = False
|
||||||
|
|
||||||
def __init__(self, request):
|
def __init__(self, request, testdir):
|
||||||
self.testdir = request.getfuncargvalue("testdir")
|
|
||||||
self.request = request
|
self.request = request
|
||||||
|
self.testdir = testdir
|
||||||
self.events = queue.Queue()
|
self.events = queue.Queue()
|
||||||
|
|
||||||
def setup(self, ):
|
def setup(self, ):
|
||||||
@@ -65,8 +65,8 @@ class SlaveSetup:
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def slave(request):
|
def slave(request, testdir):
|
||||||
return SlaveSetup(request)
|
return SlaveSetup(request, testdir)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.xfail(reason='#59')
|
@pytest.mark.xfail(reason='#59')
|
||||||
@@ -86,12 +86,76 @@ class TestReportSerialization:
|
|||||||
""")
|
""")
|
||||||
reports = reprec.getreports("pytest_runtest_logreport")
|
reports = reprec.getreports("pytest_runtest_logreport")
|
||||||
assert len(reports) == 3
|
assert len(reports) == 3
|
||||||
initial_failure_report = reports[1]
|
rep = reports[1]
|
||||||
d = serialize_report(initial_failure_report)
|
added_section = ('Failure Metadata', str("metadata metadata"), "*")
|
||||||
|
rep.longrepr.sections.append(added_section)
|
||||||
|
d = serialize_report(rep)
|
||||||
check_marshallable(d)
|
check_marshallable(d)
|
||||||
processed_report = unserialize_report("testreport", d)
|
a = unserialize_report("testreport", d)
|
||||||
assert 'Expected Message' \
|
# Check assembled == rep
|
||||||
in processed_report.longrepr.reprcrash.message
|
assert a.__dict__.keys() == rep.__dict__.keys()
|
||||||
|
for key in rep.__dict__.keys():
|
||||||
|
if key != 'longrepr':
|
||||||
|
assert getattr(a, key) == getattr(rep, key)
|
||||||
|
assert rep.longrepr.reprcrash.lineno == a.longrepr.reprcrash.lineno
|
||||||
|
assert rep.longrepr.reprcrash.message == a.longrepr.reprcrash.message
|
||||||
|
assert rep.longrepr.reprcrash.path == a.longrepr.reprcrash.path
|
||||||
|
assert rep.longrepr.reprtraceback.entrysep \
|
||||||
|
== a.longrepr.reprtraceback.entrysep
|
||||||
|
assert rep.longrepr.reprtraceback.extraline \
|
||||||
|
== a.longrepr.reprtraceback.extraline
|
||||||
|
assert rep.longrepr.reprtraceback.style \
|
||||||
|
== a.longrepr.reprtraceback.style
|
||||||
|
assert rep.longrepr.sections == a.longrepr.sections
|
||||||
|
assert rep.longrepr.reprtraceback.reprentries \
|
||||||
|
== a.longrepr.reprtraceback.reprentries
|
||||||
|
# Missing section attribute PR171
|
||||||
|
assert added_section in a.longrepr.sections
|
||||||
|
|
||||||
|
def test_reprentries_serialization_170(self, testdir):
|
||||||
|
from _pytest._code.code import ReprEntry
|
||||||
|
reprec = testdir.inline_runsource("""
|
||||||
|
def test_repr_entry():
|
||||||
|
x = 0
|
||||||
|
assert x
|
||||||
|
""", '--showlocals')
|
||||||
|
reports = reprec.getreports("pytest_runtest_logreport")
|
||||||
|
assert len(reports) == 3
|
||||||
|
rep = reports[1]
|
||||||
|
d = serialize_report(rep)
|
||||||
|
a = unserialize_report("testreport", d)
|
||||||
|
|
||||||
|
rep_entries = rep.longrepr.reprtraceback.reprentries
|
||||||
|
a_entries = a.longrepr.reprtraceback.reprentries
|
||||||
|
assert rep_entries == a_entries
|
||||||
|
for i in range(len(a_entries)):
|
||||||
|
assert isinstance(rep_entries[i], ReprEntry)
|
||||||
|
assert rep_entries[i].lines == a_entries[i].lines
|
||||||
|
assert rep_entries[i].localssep == a_entries[i].localssep
|
||||||
|
assert rep_entries[i].reprfileloc == a_entries[i].reprfileloc
|
||||||
|
assert rep_entries[i].reprfuncargs == a_entries[i].reprfuncargs
|
||||||
|
assert rep_entries[i].reprlocals == a_entries[i].reprlocals
|
||||||
|
assert rep_entries[i].style == a_entries[i].style
|
||||||
|
|
||||||
|
def test_reprentries_serialization_196(self, testdir):
|
||||||
|
from _pytest._code.code import ReprEntryNative
|
||||||
|
reprec = testdir.inline_runsource("""
|
||||||
|
def test_repr_entry_native():
|
||||||
|
x = 0
|
||||||
|
assert x
|
||||||
|
""", '--tb=native')
|
||||||
|
reports = reprec.getreports("pytest_runtest_logreport")
|
||||||
|
assert len(reports) == 3
|
||||||
|
rep = reports[1]
|
||||||
|
d = serialize_report(rep)
|
||||||
|
a = unserialize_report("testreport", d)
|
||||||
|
|
||||||
|
rep_entries = rep.longrepr.reprtraceback.reprentries
|
||||||
|
a_entries = a.longrepr.reprtraceback.reprentries
|
||||||
|
assert rep_entries == a_entries
|
||||||
|
for i in range(len(a_entries)):
|
||||||
|
assert isinstance(rep_entries[i], ReprEntryNative)
|
||||||
|
assert rep_entries[i].lines == a_entries[i].lines
|
||||||
|
|
||||||
def test_itemreport_outcomes(self, testdir):
|
def test_itemreport_outcomes(self, testdir):
|
||||||
reprec = testdir.inline_runsource("""
|
reprec = testdir.inline_runsource("""
|
||||||
@@ -277,6 +341,15 @@ class TestSlaveInteractor:
|
|||||||
("pytest_collectreport", "report.collector.fspath == bbb"),
|
("pytest_collectreport", "report.collector.fspath == bbb"),
|
||||||
])
|
])
|
||||||
|
|
||||||
|
def test_process_from_remote_error_handling(self, slave, capsys):
|
||||||
|
slave.use_callback = True
|
||||||
|
slave.setup()
|
||||||
|
slave.slp.process_from_remote(('<nonono>', ()))
|
||||||
|
out, err = capsys.readouterr()
|
||||||
|
assert 'INTERNALERROR> ValueError: unknown event: <nonono>' in out
|
||||||
|
ev = slave.popevent()
|
||||||
|
assert ev.name == "errordown"
|
||||||
|
|
||||||
|
|
||||||
def test_remote_env_vars(testdir):
|
def test_remote_env_vars(testdir):
|
||||||
testdir.makepyfile('''
|
testdir.makepyfile('''
|
||||||
|
|||||||
6
tox.ini
6
tox.ini
@@ -1,8 +1,8 @@
|
|||||||
[tox]
|
[tox]
|
||||||
# if you change the envlist, please update .travis.yml file as well
|
# if you change the envlist, please update .travis.yml file as well
|
||||||
envlist=
|
envlist=
|
||||||
py{26,27,34,35,36}-pytest{30}
|
py{26,27,34,35,36}-pytest{30,31,32}
|
||||||
py{27,35}-pytest{30}-pexpect
|
py{27,36}-pytest{30,31,32}-pexpect
|
||||||
flakes
|
flakes
|
||||||
readme
|
readme
|
||||||
|
|
||||||
@@ -15,6 +15,8 @@ deps =
|
|||||||
# to avoid .eggs
|
# to avoid .eggs
|
||||||
setuptools_scm
|
setuptools_scm
|
||||||
pytest30: pytest~=3.0.5
|
pytest30: pytest~=3.0.5
|
||||||
|
pytest31: pytest~=3.1.0
|
||||||
|
pytest32: pytest~=3.2.0
|
||||||
pexpect: pexpect
|
pexpect: pexpect
|
||||||
platform=
|
platform=
|
||||||
pexpect: linux|darwin
|
pexpect: linux|darwin
|
||||||
|
|||||||
@@ -1,60 +0,0 @@
|
|||||||
|
|
||||||
import py
|
|
||||||
|
|
||||||
|
|
||||||
def pytest_addoption(parser):
|
|
||||||
group = parser.getgroup("xdist", "distributed and subprocess testing")
|
|
||||||
group.addoption(
|
|
||||||
'--boxed',
|
|
||||||
action="store_true", dest="boxed", default=False,
|
|
||||||
help="box each test run in a separate process (unix)")
|
|
||||||
|
|
||||||
|
|
||||||
def pytest_runtest_protocol(item):
|
|
||||||
if item.config.getvalue("boxed"):
|
|
||||||
reports = forked_run_report(item)
|
|
||||||
for rep in reports:
|
|
||||||
item.ihook.pytest_runtest_logreport(report=rep)
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def forked_run_report(item):
|
|
||||||
# for now, we run setup/teardown in the subprocess
|
|
||||||
# XXX optionally allow sharing of setup/teardown
|
|
||||||
from _pytest.runner import runtestprotocol
|
|
||||||
EXITSTATUS_TESTEXIT = 4
|
|
||||||
import marshal
|
|
||||||
from xdist.remote import serialize_report
|
|
||||||
from xdist.slavemanage import unserialize_report
|
|
||||||
|
|
||||||
def runforked():
|
|
||||||
try:
|
|
||||||
reports = runtestprotocol(item, log=False)
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
py.std.os._exit(EXITSTATUS_TESTEXIT)
|
|
||||||
return marshal.dumps([serialize_report(x) for x in reports])
|
|
||||||
|
|
||||||
ff = py.process.ForkedFunc(runforked)
|
|
||||||
result = ff.waitfinish()
|
|
||||||
if result.retval is not None:
|
|
||||||
report_dumps = marshal.loads(result.retval)
|
|
||||||
return [unserialize_report("testreport", x) for x in report_dumps]
|
|
||||||
else:
|
|
||||||
if result.exitstatus == EXITSTATUS_TESTEXIT:
|
|
||||||
py.test.exit("forked test item %s raised Exit" % (item,))
|
|
||||||
return [report_process_crash(item, result)]
|
|
||||||
|
|
||||||
|
|
||||||
def report_process_crash(item, result):
|
|
||||||
path, lineno = item._getfslineno()
|
|
||||||
info = ("%s:%s: running the test CRASHED with signal %d" %
|
|
||||||
(path, lineno, result.signal))
|
|
||||||
from _pytest import runner
|
|
||||||
call = runner.CallInfo(lambda: 0/0, "???")
|
|
||||||
call.excinfo = info
|
|
||||||
rep = runner.pytest_runtest_makereport(item, call)
|
|
||||||
if result.out:
|
|
||||||
rep.sections.append(("captured stdout", result.out))
|
|
||||||
if result.err:
|
|
||||||
rep.sections.append(("captured stderr", result.err))
|
|
||||||
return rep
|
|
||||||
@@ -1,445 +1,17 @@
|
|||||||
import difflib
|
|
||||||
import itertools
|
|
||||||
from _pytest.runner import CollectReport
|
|
||||||
|
|
||||||
import pytest
|
|
||||||
import py
|
import py
|
||||||
from xdist.slavemanage import NodeManager, parse_spec_config
|
import pytest
|
||||||
|
|
||||||
|
from xdist.slavemanage import NodeManager
|
||||||
|
from xdist.scheduler import (
|
||||||
|
EachScheduling,
|
||||||
|
LoadScheduling,
|
||||||
|
LoadScopeScheduling,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
queue = py.builtin._tryimport('queue', 'Queue')
|
queue = py.builtin._tryimport('queue', 'Queue')
|
||||||
|
|
||||||
|
|
||||||
class EachScheduling:
|
|
||||||
"""Implement scheduling of test items on all nodes
|
|
||||||
|
|
||||||
If a node gets added after the test run is started then it is
|
|
||||||
assumed to replace a node which got removed before it finished
|
|
||||||
its collection. In this case it will only be used if a node
|
|
||||||
with the same spec got removed earlier.
|
|
||||||
|
|
||||||
Any nodes added after the run is started will only get items
|
|
||||||
assigned if a node with a matching spec was removed before it
|
|
||||||
finished all its pending items. The new node will then be
|
|
||||||
assigned the remaining items from the removed node.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self, config, log=None):
|
|
||||||
self.config = config
|
|
||||||
self.numnodes = len(parse_spec_config(config))
|
|
||||||
self.node2collection = {}
|
|
||||||
self.node2pending = {}
|
|
||||||
self._started = []
|
|
||||||
self._removed2pending = {}
|
|
||||||
if log is None:
|
|
||||||
self.log = py.log.Producer("eachsched")
|
|
||||||
else:
|
|
||||||
self.log = log.eachsched
|
|
||||||
self.collection_is_completed = False
|
|
||||||
|
|
||||||
@property
|
|
||||||
def nodes(self):
|
|
||||||
"""A list of all nodes in the scheduler."""
|
|
||||||
return list(self.node2pending.keys())
|
|
||||||
|
|
||||||
@property
|
|
||||||
def tests_finished(self):
|
|
||||||
if not self.collection_is_completed:
|
|
||||||
return False
|
|
||||||
if self._removed2pending:
|
|
||||||
return False
|
|
||||||
for pending in self.node2pending.values():
|
|
||||||
if len(pending) >= 2:
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
@property
|
|
||||||
def has_pending(self):
|
|
||||||
"""Return True if there are pending test items
|
|
||||||
|
|
||||||
This indicates that collection has finished and nodes are
|
|
||||||
still processing test items, so this can be thought of as
|
|
||||||
"the scheduler is active".
|
|
||||||
"""
|
|
||||||
for pending in self.node2pending.values():
|
|
||||||
if pending:
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
def add_node(self, node):
|
|
||||||
assert node not in self.node2pending
|
|
||||||
self.node2pending[node] = []
|
|
||||||
|
|
||||||
def add_node_collection(self, node, collection):
|
|
||||||
"""Add the collected test items from a node
|
|
||||||
|
|
||||||
Collection is complete once all nodes have submitted their
|
|
||||||
collection. In this case its pending list is set to an empty
|
|
||||||
list. When the collection is already completed this
|
|
||||||
submission is from a node which was restarted to replace a
|
|
||||||
dead node. In this case we already assign the pending items
|
|
||||||
here. In either case ``.schedule()`` will instruct the
|
|
||||||
node to start running the required tests.
|
|
||||||
"""
|
|
||||||
assert node in self.node2pending
|
|
||||||
if not self.collection_is_completed:
|
|
||||||
self.node2collection[node] = list(collection)
|
|
||||||
self.node2pending[node] = []
|
|
||||||
if len(self.node2collection) >= self.numnodes:
|
|
||||||
self.collection_is_completed = True
|
|
||||||
elif self._removed2pending:
|
|
||||||
for deadnode in self._removed2pending:
|
|
||||||
if deadnode.gateway.spec == node.gateway.spec:
|
|
||||||
dead_collection = self.node2collection[deadnode]
|
|
||||||
if collection != dead_collection:
|
|
||||||
msg = report_collection_diff(dead_collection,
|
|
||||||
collection,
|
|
||||||
deadnode.gateway.id,
|
|
||||||
node.gateway.id)
|
|
||||||
self.log(msg)
|
|
||||||
return
|
|
||||||
pending = self._removed2pending.pop(deadnode)
|
|
||||||
self.node2pending[node] = pending
|
|
||||||
break
|
|
||||||
|
|
||||||
def mark_test_complete(self, node, item_index, duration=0):
|
|
||||||
self.node2pending[node].remove(item_index)
|
|
||||||
|
|
||||||
def remove_node(self, node):
|
|
||||||
# KeyError if we didn't get an add_node() yet
|
|
||||||
pending = self.node2pending.pop(node)
|
|
||||||
if not pending:
|
|
||||||
return
|
|
||||||
crashitem = self.node2collection[node][pending.pop(0)]
|
|
||||||
if pending:
|
|
||||||
self._removed2pending[node] = pending
|
|
||||||
return crashitem
|
|
||||||
|
|
||||||
def schedule(self):
|
|
||||||
"""Schedule the test items on the nodes
|
|
||||||
|
|
||||||
If the node's pending list is empty it is a new node which
|
|
||||||
needs to run all the tests. If the pending list is already
|
|
||||||
populated (by ``.add_node_collection()``) then it replaces a
|
|
||||||
dead node and we only need to run those tests.
|
|
||||||
"""
|
|
||||||
assert self.collection_is_completed
|
|
||||||
for node, pending in self.node2pending.items():
|
|
||||||
if node in self._started:
|
|
||||||
continue
|
|
||||||
if not pending:
|
|
||||||
pending[:] = range(len(self.node2collection[node]))
|
|
||||||
node.send_runtest_all()
|
|
||||||
else:
|
|
||||||
node.send_runtest_some(pending)
|
|
||||||
self._started.append(node)
|
|
||||||
|
|
||||||
|
|
||||||
class LoadScheduling:
|
|
||||||
"""Implement load scheduling across nodes.
|
|
||||||
|
|
||||||
This distributes the tests collected across all nodes so each test
|
|
||||||
is run just once. All nodes collect and submit the test suite and
|
|
||||||
when all collections are received it is verified they are
|
|
||||||
identical collections. Then the collection gets divided up in
|
|
||||||
chunks and chunks get submitted to nodes. Whenever a node finishes
|
|
||||||
an item, it calls ``.mark_test_complete()`` which will trigger the
|
|
||||||
scheduler to assign more tests if the number of pending tests for
|
|
||||||
the node falls below a low-watermark.
|
|
||||||
|
|
||||||
When created, ``numnodes`` defines how many nodes are expected to
|
|
||||||
submit a collection. This is used to know when all nodes have
|
|
||||||
finished collection or how large the chunks need to be created.
|
|
||||||
|
|
||||||
Attributes:
|
|
||||||
|
|
||||||
:numnodes: The expected number of nodes taking part. The actual
|
|
||||||
number of nodes will vary during the scheduler's lifetime as
|
|
||||||
nodes are added by the DSession as they are brought up and
|
|
||||||
removed either because of a dead node or normal shutdown. This
|
|
||||||
number is primarily used to know when the initial collection is
|
|
||||||
completed.
|
|
||||||
|
|
||||||
:node2collection: Map of nodes and their test collection. All
|
|
||||||
collections should always be identical.
|
|
||||||
|
|
||||||
:node2pending: Map of nodes and the indices of their pending
|
|
||||||
tests. The indices are an index into ``.pending`` (which is
|
|
||||||
identical to their own collection stored in
|
|
||||||
``.node2collection``).
|
|
||||||
|
|
||||||
:collection: The one collection once it is validated to be
|
|
||||||
identical between all the nodes. It is initialised to None
|
|
||||||
until ``.schedule()`` is called.
|
|
||||||
|
|
||||||
:pending: List of indices of globally pending tests. These are
|
|
||||||
tests which have not yet been allocated to a chunk for a node
|
|
||||||
to process.
|
|
||||||
|
|
||||||
:log: A py.log.Producer instance.
|
|
||||||
|
|
||||||
:config: Config object, used for handling hooks.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self, config, log=None):
|
|
||||||
self.numnodes = len(parse_spec_config(config))
|
|
||||||
self.node2collection = {}
|
|
||||||
self.node2pending = {}
|
|
||||||
self.pending = []
|
|
||||||
self.collection = None
|
|
||||||
if log is None:
|
|
||||||
self.log = py.log.Producer("loadsched")
|
|
||||||
else:
|
|
||||||
self.log = log.loadsched
|
|
||||||
self.config = config
|
|
||||||
|
|
||||||
@property
|
|
||||||
def nodes(self):
|
|
||||||
"""A list of all nodes in the scheduler."""
|
|
||||||
return list(self.node2pending.keys())
|
|
||||||
|
|
||||||
@property
|
|
||||||
def collection_is_completed(self):
|
|
||||||
"""Boolean indication initial test collection is complete.
|
|
||||||
|
|
||||||
This is a boolean indicating all initial participating nodes
|
|
||||||
have finished collection. The required number of initial
|
|
||||||
nodes is defined by ``.numnodes``.
|
|
||||||
"""
|
|
||||||
return len(self.node2collection) >= self.numnodes
|
|
||||||
|
|
||||||
@property
|
|
||||||
def tests_finished(self):
|
|
||||||
"""Return True if all tests have been executed by the nodes."""
|
|
||||||
if not self.collection_is_completed:
|
|
||||||
return False
|
|
||||||
if self.pending:
|
|
||||||
return False
|
|
||||||
for pending in self.node2pending.values():
|
|
||||||
if len(pending) >= 2:
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
@property
|
|
||||||
def has_pending(self):
|
|
||||||
"""Return True if there are pending test items
|
|
||||||
|
|
||||||
This indicates that collection has finished and nodes are
|
|
||||||
still processing test items, so this can be thought of as
|
|
||||||
"the scheduler is active".
|
|
||||||
"""
|
|
||||||
if self.pending:
|
|
||||||
return True
|
|
||||||
for pending in self.node2pending.values():
|
|
||||||
if pending:
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
def add_node(self, node):
|
|
||||||
"""Add a new node to the scheduler.
|
|
||||||
|
|
||||||
From now on the node will be allocated chunks of tests to
|
|
||||||
execute.
|
|
||||||
|
|
||||||
Called by the ``DSession.slave_slaveready`` hook when it
|
|
||||||
successfully bootstraps a new node.
|
|
||||||
"""
|
|
||||||
assert node not in self.node2pending
|
|
||||||
self.node2pending[node] = []
|
|
||||||
|
|
||||||
def add_node_collection(self, node, collection):
|
|
||||||
"""Add the collected test items from a node
|
|
||||||
|
|
||||||
The collection is stored in the ``.node2collection`` map.
|
|
||||||
Called by the ``DSession.slave_collectionfinish`` hook.
|
|
||||||
"""
|
|
||||||
assert node in self.node2pending
|
|
||||||
if self.collection_is_completed:
|
|
||||||
# A new node has been added later, perhaps an original one died.
|
|
||||||
# .schedule() should have
|
|
||||||
# been called by now
|
|
||||||
assert self.collection
|
|
||||||
if collection != self.collection:
|
|
||||||
other_node = next(iter(self.node2collection.keys()))
|
|
||||||
msg = report_collection_diff(self.collection,
|
|
||||||
collection,
|
|
||||||
other_node.gateway.id,
|
|
||||||
node.gateway.id)
|
|
||||||
self.log(msg)
|
|
||||||
return
|
|
||||||
self.node2collection[node] = list(collection)
|
|
||||||
|
|
||||||
def mark_test_complete(self, node, item_index, duration=0):
|
|
||||||
"""Mark test item as completed by node
|
|
||||||
|
|
||||||
The duration it took to execute the item is used as a hint to
|
|
||||||
the scheduler.
|
|
||||||
|
|
||||||
This is called by the ``DSession.slave_testreport`` hook.
|
|
||||||
"""
|
|
||||||
self.node2pending[node].remove(item_index)
|
|
||||||
self.check_schedule(node, duration=duration)
|
|
||||||
|
|
||||||
def check_schedule(self, node, duration=0):
|
|
||||||
"""Maybe schedule new items on the node
|
|
||||||
|
|
||||||
If there are any globally pending nodes left then this will
|
|
||||||
check if the given node should be given any more tests. The
|
|
||||||
``duration`` of the last test is optionally used as a
|
|
||||||
heuristic to influence how many tests the node is assigned.
|
|
||||||
"""
|
|
||||||
if node.shutting_down:
|
|
||||||
return
|
|
||||||
|
|
||||||
if self.pending:
|
|
||||||
# how many nodes do we have?
|
|
||||||
num_nodes = len(self.node2pending)
|
|
||||||
# if our node goes below a heuristic minimum, fill it out to
|
|
||||||
# heuristic maximum
|
|
||||||
items_per_node_min = max(2, len(self.pending) // num_nodes // 4)
|
|
||||||
items_per_node_max = max(2, len(self.pending) // num_nodes // 2)
|
|
||||||
node_pending = self.node2pending[node]
|
|
||||||
if len(node_pending) < items_per_node_min:
|
|
||||||
if duration >= 0.1 and len(node_pending) >= 2:
|
|
||||||
# seems the node is doing long-running tests
|
|
||||||
# and has enough items to continue
|
|
||||||
# so let's rather wait with sending new items
|
|
||||||
return
|
|
||||||
num_send = items_per_node_max - len(node_pending)
|
|
||||||
self._send_tests(node, num_send)
|
|
||||||
self.log("num items waiting for node:", len(self.pending))
|
|
||||||
|
|
||||||
def remove_node(self, node):
|
|
||||||
"""Remove a node from the scheduler
|
|
||||||
|
|
||||||
This should be called either when the node crashed or at
|
|
||||||
shutdown time. In the former case any pending items assigned
|
|
||||||
to the node will be re-scheduled. Called by the
|
|
||||||
``DSession.slave_slavefinished`` and
|
|
||||||
``DSession.slave_errordown`` hooks.
|
|
||||||
|
|
||||||
Return the item which was being executing while the node
|
|
||||||
crashed or None if the node has no more pending items.
|
|
||||||
|
|
||||||
"""
|
|
||||||
pending = self.node2pending.pop(node)
|
|
||||||
if not pending:
|
|
||||||
return
|
|
||||||
|
|
||||||
# The node crashed, reassing pending items
|
|
||||||
crashitem = self.collection[pending.pop(0)]
|
|
||||||
self.pending.extend(pending)
|
|
||||||
for node in self.node2pending:
|
|
||||||
self.check_schedule(node)
|
|
||||||
return crashitem
|
|
||||||
|
|
||||||
def schedule(self):
|
|
||||||
"""Initiate distribution of the test collection
|
|
||||||
|
|
||||||
Initiate scheduling of the items across the nodes. If this
|
|
||||||
gets called again later it behaves the same as calling
|
|
||||||
``.check_schedule()`` on all nodes so that newly added nodes
|
|
||||||
will start to be used.
|
|
||||||
|
|
||||||
This is called by the ``DSession.slave_collectionfinish`` hook
|
|
||||||
if ``.collection_is_completed`` is True.
|
|
||||||
"""
|
|
||||||
assert self.collection_is_completed
|
|
||||||
|
|
||||||
# Initial distribution already happened, reschedule on all nodes
|
|
||||||
if self.collection is not None:
|
|
||||||
for node in self.nodes:
|
|
||||||
self.check_schedule(node)
|
|
||||||
return
|
|
||||||
|
|
||||||
# XXX allow nodes to have different collections
|
|
||||||
if not self._check_nodes_have_same_collection():
|
|
||||||
self.log('**Different tests collected, aborting run**')
|
|
||||||
return
|
|
||||||
|
|
||||||
# Collections are identical, create the index of pending items.
|
|
||||||
self.collection = list(self.node2collection.values())[0]
|
|
||||||
self.pending[:] = range(len(self.collection))
|
|
||||||
if not self.collection:
|
|
||||||
return
|
|
||||||
|
|
||||||
# Send a batch of tests to run. If we don't have at least two
|
|
||||||
# tests per node, we have to send them all so that we can send
|
|
||||||
# shutdown signals and get all nodes working.
|
|
||||||
initial_batch = max(len(self.pending) // 4,
|
|
||||||
2 * len(self.nodes))
|
|
||||||
|
|
||||||
# distribute tests round-robin up to the batch size
|
|
||||||
# (or until we run out)
|
|
||||||
nodes = itertools.cycle(self.nodes)
|
|
||||||
for i in range(initial_batch):
|
|
||||||
self._send_tests(next(nodes), 1)
|
|
||||||
|
|
||||||
if not self.pending:
|
|
||||||
# initial distribution sent all tests, start node shutdown
|
|
||||||
for node in self.nodes:
|
|
||||||
node.shutdown()
|
|
||||||
|
|
||||||
def _send_tests(self, node, num):
|
|
||||||
tests_per_node = self.pending[:num]
|
|
||||||
if tests_per_node:
|
|
||||||
del self.pending[:num]
|
|
||||||
self.node2pending[node].extend(tests_per_node)
|
|
||||||
node.send_runtest_some(tests_per_node)
|
|
||||||
|
|
||||||
def _check_nodes_have_same_collection(self):
|
|
||||||
"""Return True if all nodes have collected the same items.
|
|
||||||
|
|
||||||
If collections differ, this method returns False while logging
|
|
||||||
the collection differences and posting collection errors to
|
|
||||||
pytest_collectreport hook.
|
|
||||||
"""
|
|
||||||
node_collection_items = list(self.node2collection.items())
|
|
||||||
first_node, col = node_collection_items[0]
|
|
||||||
same_collection = True
|
|
||||||
for node, collection in node_collection_items[1:]:
|
|
||||||
msg = report_collection_diff(
|
|
||||||
col,
|
|
||||||
collection,
|
|
||||||
first_node.gateway.id,
|
|
||||||
node.gateway.id,
|
|
||||||
)
|
|
||||||
if msg:
|
|
||||||
same_collection = False
|
|
||||||
self.log(msg)
|
|
||||||
if self.config is not None:
|
|
||||||
rep = CollectReport(
|
|
||||||
node.gateway.id, 'failed',
|
|
||||||
longrepr=msg, result=[])
|
|
||||||
self.config.hook.pytest_collectreport(report=rep)
|
|
||||||
|
|
||||||
return same_collection
|
|
||||||
|
|
||||||
|
|
||||||
def report_collection_diff(from_collection, to_collection, from_id, to_id):
|
|
||||||
"""Report the collected test difference between two nodes.
|
|
||||||
|
|
||||||
:returns: detailed message describing the difference between the given
|
|
||||||
collections, or None if they are equal.
|
|
||||||
"""
|
|
||||||
if from_collection == to_collection:
|
|
||||||
return None
|
|
||||||
|
|
||||||
diff = difflib.unified_diff(
|
|
||||||
from_collection,
|
|
||||||
to_collection,
|
|
||||||
fromfile=from_id,
|
|
||||||
tofile=to_id,
|
|
||||||
)
|
|
||||||
error_message = py.builtin._totext(
|
|
||||||
'Different tests were collected between {from_id} and {to_id}. '
|
|
||||||
'The difference is:\n'
|
|
||||||
'{diff}'
|
|
||||||
).format(from_id=from_id, to_id=to_id, diff='\n'.join(diff))
|
|
||||||
msg = "\n".join([x.rstrip() for x in error_message.split("\n")])
|
|
||||||
return msg
|
|
||||||
|
|
||||||
|
|
||||||
class Interrupted(KeyboardInterrupt):
|
class Interrupted(KeyboardInterrupt):
|
||||||
""" signals an immediate interruption. """
|
""" signals an immediate interruption. """
|
||||||
|
|
||||||
@@ -457,6 +29,7 @@ class DSession:
|
|||||||
automatically starts collecting tests. Once tests are collected
|
automatically starts collecting tests. Once tests are collected
|
||||||
it will wait for instructions.
|
it will wait for instructions.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
self.config = config
|
self.config = config
|
||||||
self.log = py.log.Producer("dsession")
|
self.log = py.log.Producer("dsession")
|
||||||
@@ -521,11 +94,13 @@ class DSession:
|
|||||||
|
|
||||||
@pytest.mark.trylast
|
@pytest.mark.trylast
|
||||||
def pytest_xdist_make_scheduler(self, config, log):
|
def pytest_xdist_make_scheduler(self, config, log):
|
||||||
dist = config.getvalue("dist")
|
dist = config.getvalue('dist')
|
||||||
if dist == "load":
|
schedulers = {
|
||||||
return LoadScheduling(config, log)
|
'each': EachScheduling,
|
||||||
elif dist == "each":
|
'load': LoadScheduling,
|
||||||
return EachScheduling(config, log)
|
'loadscope': LoadScopeScheduling,
|
||||||
|
}
|
||||||
|
return schedulers[dist](config, log)
|
||||||
|
|
||||||
def pytest_runtestloop(self):
|
def pytest_runtestloop(self):
|
||||||
self.sched = self.config.hook.pytest_xdist_make_scheduler(
|
self.sched = self.config.hook.pytest_xdist_make_scheduler(
|
||||||
@@ -672,6 +247,11 @@ class DSession:
|
|||||||
if rep.failed:
|
if rep.failed:
|
||||||
self._failed_slave_collectreport(node, rep)
|
self._failed_slave_collectreport(node, rep)
|
||||||
|
|
||||||
|
def slave_logwarning(self, message, code, nodeid, fslocation):
|
||||||
|
"""Emitted when a node calls the pytest_logwarning hook."""
|
||||||
|
kwargs = dict(message=message, code=code, nodeid=nodeid, fslocation=fslocation)
|
||||||
|
self.config.hook.pytest_logwarning.call_historic(kwargs=kwargs)
|
||||||
|
|
||||||
def _clone_node(self, node):
|
def _clone_node(self, node):
|
||||||
"""Return new node based on an existing one.
|
"""Return new node based on an existing one.
|
||||||
|
|
||||||
@@ -746,7 +326,7 @@ class TerminalDistReporter:
|
|||||||
return " / ".join(parts)
|
return " / ".join(parts)
|
||||||
|
|
||||||
def rewrite(self, line, newline=False):
|
def rewrite(self, line, newline=False):
|
||||||
pline = line + " " * max(self._lastlen-len(line), 0)
|
pline = line + " " * max(self._lastlen - len(line), 0)
|
||||||
if newline:
|
if newline:
|
||||||
self._lastlen = 0
|
self._lastlen = 0
|
||||||
pline += "\n"
|
pline += "\n"
|
||||||
|
|||||||
@@ -26,18 +26,21 @@ def pytest_addoption(parser):
|
|||||||
help="shortcut for '--dist=load --tx=NUM*popen', "
|
help="shortcut for '--dist=load --tx=NUM*popen', "
|
||||||
"you can use 'auto' here for auto detection CPUs number on "
|
"you can use 'auto' here for auto detection CPUs number on "
|
||||||
"host system")
|
"host system")
|
||||||
group._addoption('--max-slave-restart', action="store", default=None,
|
group.addoption('--max-slave-restart', action="store", default=None,
|
||||||
help="maximum number of slaves that can be restarted "
|
help="maximum number of slaves that can be restarted "
|
||||||
"when crashed (set to zero to disable this feature)")
|
"when crashed (set to zero to disable this feature)")
|
||||||
group._addoption(
|
group.addoption(
|
||||||
'--dist', metavar="distmode",
|
'--dist', metavar="distmode",
|
||||||
action="store", choices=['load', 'each', 'no'],
|
action="store", choices=['each', 'load', 'loadscope', 'no'],
|
||||||
dest="dist", default="no",
|
dest="dist", default="no",
|
||||||
help=("set mode for distributing tests to exec environments.\n\n"
|
help=("set mode for distributing tests to exec environments.\n\n"
|
||||||
"each: send each test to each available environment.\n\n"
|
"each: send each test to all available environments.\n\n"
|
||||||
"load: send each test to available environment.\n\n"
|
"load: load balance by sending any pending test to any"
|
||||||
|
" available environment.\n\n"
|
||||||
|
"loadscope: load balance by sending pending groups of tests in"
|
||||||
|
" the same scope to any available environment.\n\n"
|
||||||
"(default) no: run tests inprocess, don't distribute."))
|
"(default) no: run tests inprocess, don't distribute."))
|
||||||
group._addoption(
|
group.addoption(
|
||||||
'--tx', dest="tx", action="append", default=[],
|
'--tx', dest="tx", action="append", default=[],
|
||||||
metavar="xspec",
|
metavar="xspec",
|
||||||
help=("add a test execution environment. some examples: "
|
help=("add a test execution environment. some examples: "
|
||||||
@@ -54,6 +57,9 @@ def pytest_addoption(parser):
|
|||||||
'--rsyncignore', action="append", default=[], metavar="GLOB",
|
'--rsyncignore', action="append", default=[], metavar="GLOB",
|
||||||
help="add expression for ignores when rsyncing to remote tx nodes.")
|
help="add expression for ignores when rsyncing to remote tx nodes.")
|
||||||
|
|
||||||
|
group.addoption(
|
||||||
|
"--boxed", action="store_true",
|
||||||
|
help="backward compatibility alias for pytest-forked --forked")
|
||||||
parser.addini(
|
parser.addini(
|
||||||
'rsyncdirs', 'list of (relative) paths to be rsynced for'
|
'rsyncdirs', 'list of (relative) paths to be rsynced for'
|
||||||
' remote distributed testing.', type="pathlist")
|
' remote distributed testing.', type="pathlist")
|
||||||
@@ -64,6 +70,7 @@ def pytest_addoption(parser):
|
|||||||
"looponfailroots", type="pathlist",
|
"looponfailroots", type="pathlist",
|
||||||
help="directories to check for changes", default=[py.path.local()])
|
help="directories to check for changes", default=[py.path.local()])
|
||||||
|
|
||||||
|
|
||||||
# -------------------------------------------------------------------------
|
# -------------------------------------------------------------------------
|
||||||
# distributed testing hooks
|
# distributed testing hooks
|
||||||
# -------------------------------------------------------------------------
|
# -------------------------------------------------------------------------
|
||||||
@@ -90,11 +97,14 @@ def pytest_configure(config):
|
|||||||
config.pluginmanager.register(session, "dsession")
|
config.pluginmanager.register(session, "dsession")
|
||||||
tr = config.pluginmanager.getplugin("terminalreporter")
|
tr = config.pluginmanager.getplugin("terminalreporter")
|
||||||
tr.showfspath = False
|
tr.showfspath = False
|
||||||
|
if config.getoption("boxed"):
|
||||||
|
config.option.forked = True
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.tryfirst
|
@pytest.mark.tryfirst
|
||||||
def pytest_cmdline_main(config):
|
def pytest_cmdline_main(config):
|
||||||
if config.option.numprocesses:
|
if config.option.numprocesses:
|
||||||
|
if config.option.dist == 'no':
|
||||||
config.option.dist = "load"
|
config.option.dist = "load"
|
||||||
config.option.tx = ['popen'] * config.option.numprocesses
|
config.option.tx = ['popen'] * config.option.numprocesses
|
||||||
if config.option.distload:
|
if config.option.distload:
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
class SlaveInteractor:
|
class SlaveInteractor:
|
||||||
@@ -33,11 +34,11 @@ class SlaveInteractor:
|
|||||||
slaveinfo = getinfodict()
|
slaveinfo = getinfodict()
|
||||||
self.sendevent("slaveready", slaveinfo=slaveinfo)
|
self.sendevent("slaveready", slaveinfo=slaveinfo)
|
||||||
|
|
||||||
def pytest_sessionfinish(self, __multicall__, exitstatus):
|
@pytest.hookimpl(hookwrapper=True)
|
||||||
|
def pytest_sessionfinish(self, exitstatus):
|
||||||
self.config.slaveoutput['exitstatus'] = exitstatus
|
self.config.slaveoutput['exitstatus'] = exitstatus
|
||||||
res = __multicall__.execute()
|
yield
|
||||||
self.sendevent("slavefinished", slaveoutput=self.config.slaveoutput)
|
self.sendevent("slavefinished", slaveoutput=self.config.slaveoutput)
|
||||||
return res
|
|
||||||
|
|
||||||
def pytest_collection(self, session):
|
def pytest_collection(self, session):
|
||||||
self.sendevent("collectionstart")
|
self.sendevent("collectionstart")
|
||||||
@@ -96,6 +97,10 @@ class SlaveInteractor:
|
|||||||
data = serialize_report(report)
|
data = serialize_report(report)
|
||||||
self.sendevent("collectreport", data=data)
|
self.sendevent("collectreport", data=data)
|
||||||
|
|
||||||
|
def pytest_logwarning(self, message, code, nodeid, fslocation):
|
||||||
|
self.sendevent("logwarning", message=message, code=code, nodeid=nodeid,
|
||||||
|
fslocation=fslocation)
|
||||||
|
|
||||||
|
|
||||||
def serialize_report(rep):
|
def serialize_report(rep):
|
||||||
def disassembled_report(rep):
|
def disassembled_report(rep):
|
||||||
@@ -104,17 +109,21 @@ def serialize_report(rep):
|
|||||||
|
|
||||||
new_entries = []
|
new_entries = []
|
||||||
for entry in reprtraceback['reprentries']:
|
for entry in reprtraceback['reprentries']:
|
||||||
new_entry = entry.__dict__
|
entry_data = {
|
||||||
for key, value in new_entry.items():
|
'type': type(entry).__name__,
|
||||||
|
'data': entry.__dict__,
|
||||||
|
}
|
||||||
|
for key, value in entry_data['data'].items():
|
||||||
if hasattr(value, '__dict__'):
|
if hasattr(value, '__dict__'):
|
||||||
new_entry[key] = value.__dict__
|
entry_data['data'][key] = value.__dict__
|
||||||
new_entries.append(new_entry)
|
new_entries.append(entry_data)
|
||||||
|
|
||||||
reprtraceback['reprentries'] = new_entries
|
reprtraceback['reprentries'] = new_entries
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'reprcrash': reprcrash,
|
'reprcrash': reprcrash,
|
||||||
'reprtraceback': reprtraceback
|
'reprtraceback': reprtraceback,
|
||||||
|
'sections': rep.longrepr.sections
|
||||||
}
|
}
|
||||||
|
|
||||||
import py
|
import py
|
||||||
|
|||||||
26
xdist/report.py
Normal file
26
xdist/report.py
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import py
|
||||||
|
from difflib import unified_diff
|
||||||
|
|
||||||
|
|
||||||
|
def report_collection_diff(from_collection, to_collection, from_id, to_id):
|
||||||
|
"""Report the collected test difference between two nodes.
|
||||||
|
|
||||||
|
:returns: detailed message describing the difference between the given
|
||||||
|
collections, or None if they are equal.
|
||||||
|
"""
|
||||||
|
if from_collection == to_collection:
|
||||||
|
return None
|
||||||
|
|
||||||
|
diff = unified_diff(
|
||||||
|
from_collection,
|
||||||
|
to_collection,
|
||||||
|
fromfile=from_id,
|
||||||
|
tofile=to_id,
|
||||||
|
)
|
||||||
|
error_message = py.builtin._totext(
|
||||||
|
'Different tests were collected between {from_id} and {to_id}. '
|
||||||
|
'The difference is:\n'
|
||||||
|
'{diff}'
|
||||||
|
).format(from_id=from_id, to_id=to_id, diff='\n'.join(diff))
|
||||||
|
msg = "\n".join([x.rstrip() for x in error_message.split("\n")])
|
||||||
|
return msg
|
||||||
3
xdist/scheduler/__init__.py
Normal file
3
xdist/scheduler/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
from xdist.scheduler.each import EachScheduling # noqa
|
||||||
|
from xdist.scheduler.load import LoadScheduling # noqa
|
||||||
|
from xdist.scheduler.loadscope import LoadScopeScheduling # noqa
|
||||||
129
xdist/scheduler/each.py
Normal file
129
xdist/scheduler/each.py
Normal file
@@ -0,0 +1,129 @@
|
|||||||
|
from py.log import Producer
|
||||||
|
|
||||||
|
from xdist.slavemanage import parse_spec_config
|
||||||
|
from xdist.report import report_collection_diff
|
||||||
|
|
||||||
|
|
||||||
|
class EachScheduling:
|
||||||
|
"""Implement scheduling of test items on all nodes
|
||||||
|
|
||||||
|
If a node gets added after the test run is started then it is
|
||||||
|
assumed to replace a node which got removed before it finished
|
||||||
|
its collection. In this case it will only be used if a node
|
||||||
|
with the same spec got removed earlier.
|
||||||
|
|
||||||
|
Any nodes added after the run is started will only get items
|
||||||
|
assigned if a node with a matching spec was removed before it
|
||||||
|
finished all its pending items. The new node will then be
|
||||||
|
assigned the remaining items from the removed node.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, config, log=None):
|
||||||
|
self.config = config
|
||||||
|
self.numnodes = len(parse_spec_config(config))
|
||||||
|
self.node2collection = {}
|
||||||
|
self.node2pending = {}
|
||||||
|
self._started = []
|
||||||
|
self._removed2pending = {}
|
||||||
|
if log is None:
|
||||||
|
self.log = Producer("eachsched")
|
||||||
|
else:
|
||||||
|
self.log = log.eachsched
|
||||||
|
self.collection_is_completed = False
|
||||||
|
|
||||||
|
@property
|
||||||
|
def nodes(self):
|
||||||
|
"""A list of all nodes in the scheduler."""
|
||||||
|
return list(self.node2pending.keys())
|
||||||
|
|
||||||
|
@property
|
||||||
|
def tests_finished(self):
|
||||||
|
if not self.collection_is_completed:
|
||||||
|
return False
|
||||||
|
if self._removed2pending:
|
||||||
|
return False
|
||||||
|
for pending in self.node2pending.values():
|
||||||
|
if len(pending) >= 2:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
@property
|
||||||
|
def has_pending(self):
|
||||||
|
"""Return True if there are pending test items
|
||||||
|
|
||||||
|
This indicates that collection has finished and nodes are
|
||||||
|
still processing test items, so this can be thought of as
|
||||||
|
"the scheduler is active".
|
||||||
|
"""
|
||||||
|
for pending in self.node2pending.values():
|
||||||
|
if pending:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def add_node(self, node):
|
||||||
|
assert node not in self.node2pending
|
||||||
|
self.node2pending[node] = []
|
||||||
|
|
||||||
|
def add_node_collection(self, node, collection):
|
||||||
|
"""Add the collected test items from a node
|
||||||
|
|
||||||
|
Collection is complete once all nodes have submitted their
|
||||||
|
collection. In this case its pending list is set to an empty
|
||||||
|
list. When the collection is already completed this
|
||||||
|
submission is from a node which was restarted to replace a
|
||||||
|
dead node. In this case we already assign the pending items
|
||||||
|
here. In either case ``.schedule()`` will instruct the
|
||||||
|
node to start running the required tests.
|
||||||
|
"""
|
||||||
|
assert node in self.node2pending
|
||||||
|
if not self.collection_is_completed:
|
||||||
|
self.node2collection[node] = list(collection)
|
||||||
|
self.node2pending[node] = []
|
||||||
|
if len(self.node2collection) >= self.numnodes:
|
||||||
|
self.collection_is_completed = True
|
||||||
|
elif self._removed2pending:
|
||||||
|
for deadnode in self._removed2pending:
|
||||||
|
if deadnode.gateway.spec == node.gateway.spec:
|
||||||
|
dead_collection = self.node2collection[deadnode]
|
||||||
|
if collection != dead_collection:
|
||||||
|
msg = report_collection_diff(dead_collection,
|
||||||
|
collection,
|
||||||
|
deadnode.gateway.id,
|
||||||
|
node.gateway.id)
|
||||||
|
self.log(msg)
|
||||||
|
return
|
||||||
|
pending = self._removed2pending.pop(deadnode)
|
||||||
|
self.node2pending[node] = pending
|
||||||
|
break
|
||||||
|
|
||||||
|
def mark_test_complete(self, node, item_index, duration=0):
|
||||||
|
self.node2pending[node].remove(item_index)
|
||||||
|
|
||||||
|
def remove_node(self, node):
|
||||||
|
# KeyError if we didn't get an add_node() yet
|
||||||
|
pending = self.node2pending.pop(node)
|
||||||
|
if not pending:
|
||||||
|
return
|
||||||
|
crashitem = self.node2collection[node][pending.pop(0)]
|
||||||
|
if pending:
|
||||||
|
self._removed2pending[node] = pending
|
||||||
|
return crashitem
|
||||||
|
|
||||||
|
def schedule(self):
|
||||||
|
"""Schedule the test items on the nodes
|
||||||
|
|
||||||
|
If the node's pending list is empty it is a new node which
|
||||||
|
needs to run all the tests. If the pending list is already
|
||||||
|
populated (by ``.add_node_collection()``) then it replaces a
|
||||||
|
dead node and we only need to run those tests.
|
||||||
|
"""
|
||||||
|
assert self.collection_is_completed
|
||||||
|
for node, pending in self.node2pending.items():
|
||||||
|
if node in self._started:
|
||||||
|
continue
|
||||||
|
if not pending:
|
||||||
|
pending[:] = range(len(self.node2collection[node]))
|
||||||
|
node.send_runtest_all()
|
||||||
|
else:
|
||||||
|
node.send_runtest_some(pending)
|
||||||
|
self._started.append(node)
|
||||||
288
xdist/scheduler/load.py
Normal file
288
xdist/scheduler/load.py
Normal file
@@ -0,0 +1,288 @@
|
|||||||
|
from itertools import cycle
|
||||||
|
|
||||||
|
from py.log import Producer
|
||||||
|
from _pytest.runner import CollectReport
|
||||||
|
|
||||||
|
from xdist.slavemanage import parse_spec_config
|
||||||
|
from xdist.report import report_collection_diff
|
||||||
|
|
||||||
|
|
||||||
|
class LoadScheduling:
|
||||||
|
"""Implement load scheduling across nodes.
|
||||||
|
|
||||||
|
This distributes the tests collected across all nodes so each test
|
||||||
|
is run just once. All nodes collect and submit the test suite and
|
||||||
|
when all collections are received it is verified they are
|
||||||
|
identical collections. Then the collection gets divided up in
|
||||||
|
chunks and chunks get submitted to nodes. Whenever a node finishes
|
||||||
|
an item, it calls ``.mark_test_complete()`` which will trigger the
|
||||||
|
scheduler to assign more tests if the number of pending tests for
|
||||||
|
the node falls below a low-watermark.
|
||||||
|
|
||||||
|
When created, ``numnodes`` defines how many nodes are expected to
|
||||||
|
submit a collection. This is used to know when all nodes have
|
||||||
|
finished collection or how large the chunks need to be created.
|
||||||
|
|
||||||
|
Attributes:
|
||||||
|
|
||||||
|
:numnodes: The expected number of nodes taking part. The actual
|
||||||
|
number of nodes will vary during the scheduler's lifetime as
|
||||||
|
nodes are added by the DSession as they are brought up and
|
||||||
|
removed either because of a dead node or normal shutdown. This
|
||||||
|
number is primarily used to know when the initial collection is
|
||||||
|
completed.
|
||||||
|
|
||||||
|
:node2collection: Map of nodes and their test collection. All
|
||||||
|
collections should always be identical.
|
||||||
|
|
||||||
|
:node2pending: Map of nodes and the indices of their pending
|
||||||
|
tests. The indices are an index into ``.pending`` (which is
|
||||||
|
identical to their own collection stored in
|
||||||
|
``.node2collection``).
|
||||||
|
|
||||||
|
:collection: The one collection once it is validated to be
|
||||||
|
identical between all the nodes. It is initialised to None
|
||||||
|
until ``.schedule()`` is called.
|
||||||
|
|
||||||
|
:pending: List of indices of globally pending tests. These are
|
||||||
|
tests which have not yet been allocated to a chunk for a node
|
||||||
|
to process.
|
||||||
|
|
||||||
|
:log: A py.log.Producer instance.
|
||||||
|
|
||||||
|
:config: Config object, used for handling hooks.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, config, log=None):
|
||||||
|
self.numnodes = len(parse_spec_config(config))
|
||||||
|
self.node2collection = {}
|
||||||
|
self.node2pending = {}
|
||||||
|
self.pending = []
|
||||||
|
self.collection = None
|
||||||
|
if log is None:
|
||||||
|
self.log = Producer("loadsched")
|
||||||
|
else:
|
||||||
|
self.log = log.loadsched
|
||||||
|
self.config = config
|
||||||
|
|
||||||
|
@property
|
||||||
|
def nodes(self):
|
||||||
|
"""A list of all nodes in the scheduler."""
|
||||||
|
return list(self.node2pending.keys())
|
||||||
|
|
||||||
|
@property
|
||||||
|
def collection_is_completed(self):
|
||||||
|
"""Boolean indication initial test collection is complete.
|
||||||
|
|
||||||
|
This is a boolean indicating all initial participating nodes
|
||||||
|
have finished collection. The required number of initial
|
||||||
|
nodes is defined by ``.numnodes``.
|
||||||
|
"""
|
||||||
|
return len(self.node2collection) >= self.numnodes
|
||||||
|
|
||||||
|
@property
|
||||||
|
def tests_finished(self):
|
||||||
|
"""Return True if all tests have been executed by the nodes."""
|
||||||
|
if not self.collection_is_completed:
|
||||||
|
return False
|
||||||
|
if self.pending:
|
||||||
|
return False
|
||||||
|
for pending in self.node2pending.values():
|
||||||
|
if len(pending) >= 2:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
@property
|
||||||
|
def has_pending(self):
|
||||||
|
"""Return True if there are pending test items
|
||||||
|
|
||||||
|
This indicates that collection has finished and nodes are
|
||||||
|
still processing test items, so this can be thought of as
|
||||||
|
"the scheduler is active".
|
||||||
|
"""
|
||||||
|
if self.pending:
|
||||||
|
return True
|
||||||
|
for pending in self.node2pending.values():
|
||||||
|
if pending:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def add_node(self, node):
|
||||||
|
"""Add a new node to the scheduler.
|
||||||
|
|
||||||
|
From now on the node will be allocated chunks of tests to
|
||||||
|
execute.
|
||||||
|
|
||||||
|
Called by the ``DSession.slave_slaveready`` hook when it
|
||||||
|
successfully bootstraps a new node.
|
||||||
|
"""
|
||||||
|
assert node not in self.node2pending
|
||||||
|
self.node2pending[node] = []
|
||||||
|
|
||||||
|
def add_node_collection(self, node, collection):
|
||||||
|
"""Add the collected test items from a node
|
||||||
|
|
||||||
|
The collection is stored in the ``.node2collection`` map.
|
||||||
|
Called by the ``DSession.slave_collectionfinish`` hook.
|
||||||
|
"""
|
||||||
|
assert node in self.node2pending
|
||||||
|
if self.collection_is_completed:
|
||||||
|
# A new node has been added later, perhaps an original one died.
|
||||||
|
# .schedule() should have
|
||||||
|
# been called by now
|
||||||
|
assert self.collection
|
||||||
|
if collection != self.collection:
|
||||||
|
other_node = next(iter(self.node2collection.keys()))
|
||||||
|
msg = report_collection_diff(self.collection,
|
||||||
|
collection,
|
||||||
|
other_node.gateway.id,
|
||||||
|
node.gateway.id)
|
||||||
|
self.log(msg)
|
||||||
|
return
|
||||||
|
self.node2collection[node] = list(collection)
|
||||||
|
|
||||||
|
def mark_test_complete(self, node, item_index, duration=0):
|
||||||
|
"""Mark test item as completed by node
|
||||||
|
|
||||||
|
The duration it took to execute the item is used as a hint to
|
||||||
|
the scheduler.
|
||||||
|
|
||||||
|
This is called by the ``DSession.slave_testreport`` hook.
|
||||||
|
"""
|
||||||
|
self.node2pending[node].remove(item_index)
|
||||||
|
self.check_schedule(node, duration=duration)
|
||||||
|
|
||||||
|
def check_schedule(self, node, duration=0):
|
||||||
|
"""Maybe schedule new items on the node
|
||||||
|
|
||||||
|
If there are any globally pending nodes left then this will
|
||||||
|
check if the given node should be given any more tests. The
|
||||||
|
``duration`` of the last test is optionally used as a
|
||||||
|
heuristic to influence how many tests the node is assigned.
|
||||||
|
"""
|
||||||
|
if node.shutting_down:
|
||||||
|
return
|
||||||
|
|
||||||
|
if self.pending:
|
||||||
|
# how many nodes do we have?
|
||||||
|
num_nodes = len(self.node2pending)
|
||||||
|
# if our node goes below a heuristic minimum, fill it out to
|
||||||
|
# heuristic maximum
|
||||||
|
items_per_node_min = max(2, len(self.pending) // num_nodes // 4)
|
||||||
|
items_per_node_max = max(2, len(self.pending) // num_nodes // 2)
|
||||||
|
node_pending = self.node2pending[node]
|
||||||
|
if len(node_pending) < items_per_node_min:
|
||||||
|
if duration >= 0.1 and len(node_pending) >= 2:
|
||||||
|
# seems the node is doing long-running tests
|
||||||
|
# and has enough items to continue
|
||||||
|
# so let's rather wait with sending new items
|
||||||
|
return
|
||||||
|
num_send = items_per_node_max - len(node_pending)
|
||||||
|
self._send_tests(node, num_send)
|
||||||
|
self.log("num items waiting for node:", len(self.pending))
|
||||||
|
|
||||||
|
def remove_node(self, node):
|
||||||
|
"""Remove a node from the scheduler
|
||||||
|
|
||||||
|
This should be called either when the node crashed or at
|
||||||
|
shutdown time. In the former case any pending items assigned
|
||||||
|
to the node will be re-scheduled. Called by the
|
||||||
|
``DSession.slave_slavefinished`` and
|
||||||
|
``DSession.slave_errordown`` hooks.
|
||||||
|
|
||||||
|
Return the item which was being executing while the node
|
||||||
|
crashed or None if the node has no more pending items.
|
||||||
|
|
||||||
|
"""
|
||||||
|
pending = self.node2pending.pop(node)
|
||||||
|
if not pending:
|
||||||
|
return
|
||||||
|
|
||||||
|
# The node crashed, reassing pending items
|
||||||
|
crashitem = self.collection[pending.pop(0)]
|
||||||
|
self.pending.extend(pending)
|
||||||
|
for node in self.node2pending:
|
||||||
|
self.check_schedule(node)
|
||||||
|
return crashitem
|
||||||
|
|
||||||
|
def schedule(self):
|
||||||
|
"""Initiate distribution of the test collection
|
||||||
|
|
||||||
|
Initiate scheduling of the items across the nodes. If this
|
||||||
|
gets called again later it behaves the same as calling
|
||||||
|
``.check_schedule()`` on all nodes so that newly added nodes
|
||||||
|
will start to be used.
|
||||||
|
|
||||||
|
This is called by the ``DSession.slave_collectionfinish`` hook
|
||||||
|
if ``.collection_is_completed`` is True.
|
||||||
|
"""
|
||||||
|
assert self.collection_is_completed
|
||||||
|
|
||||||
|
# Initial distribution already happened, reschedule on all nodes
|
||||||
|
if self.collection is not None:
|
||||||
|
for node in self.nodes:
|
||||||
|
self.check_schedule(node)
|
||||||
|
return
|
||||||
|
|
||||||
|
# XXX allow nodes to have different collections
|
||||||
|
if not self._check_nodes_have_same_collection():
|
||||||
|
self.log('**Different tests collected, aborting run**')
|
||||||
|
return
|
||||||
|
|
||||||
|
# Collections are identical, create the index of pending items.
|
||||||
|
self.collection = list(self.node2collection.values())[0]
|
||||||
|
self.pending[:] = range(len(self.collection))
|
||||||
|
if not self.collection:
|
||||||
|
return
|
||||||
|
|
||||||
|
# Send a batch of tests to run. If we don't have at least two
|
||||||
|
# tests per node, we have to send them all so that we can send
|
||||||
|
# shutdown signals and get all nodes working.
|
||||||
|
initial_batch = max(len(self.pending) // 4,
|
||||||
|
2 * len(self.nodes))
|
||||||
|
|
||||||
|
# distribute tests round-robin up to the batch size
|
||||||
|
# (or until we run out)
|
||||||
|
nodes = cycle(self.nodes)
|
||||||
|
for i in range(initial_batch):
|
||||||
|
self._send_tests(next(nodes), 1)
|
||||||
|
|
||||||
|
if not self.pending:
|
||||||
|
# initial distribution sent all tests, start node shutdown
|
||||||
|
for node in self.nodes:
|
||||||
|
node.shutdown()
|
||||||
|
|
||||||
|
def _send_tests(self, node, num):
|
||||||
|
tests_per_node = self.pending[:num]
|
||||||
|
if tests_per_node:
|
||||||
|
del self.pending[:num]
|
||||||
|
self.node2pending[node].extend(tests_per_node)
|
||||||
|
node.send_runtest_some(tests_per_node)
|
||||||
|
|
||||||
|
def _check_nodes_have_same_collection(self):
|
||||||
|
"""Return True if all nodes have collected the same items.
|
||||||
|
|
||||||
|
If collections differ, this method returns False while logging
|
||||||
|
the collection differences and posting collection errors to
|
||||||
|
pytest_collectreport hook.
|
||||||
|
"""
|
||||||
|
node_collection_items = list(self.node2collection.items())
|
||||||
|
first_node, col = node_collection_items[0]
|
||||||
|
same_collection = True
|
||||||
|
for node, collection in node_collection_items[1:]:
|
||||||
|
msg = report_collection_diff(
|
||||||
|
col,
|
||||||
|
collection,
|
||||||
|
first_node.gateway.id,
|
||||||
|
node.gateway.id,
|
||||||
|
)
|
||||||
|
if msg:
|
||||||
|
same_collection = False
|
||||||
|
self.log(msg)
|
||||||
|
if self.config is not None:
|
||||||
|
rep = CollectReport(
|
||||||
|
node.gateway.id, 'failed',
|
||||||
|
longrepr=msg, result=[])
|
||||||
|
self.config.hook.pytest_collectreport(report=rep)
|
||||||
|
|
||||||
|
return same_collection
|
||||||
428
xdist/scheduler/loadscope.py
Normal file
428
xdist/scheduler/loadscope.py
Normal file
@@ -0,0 +1,428 @@
|
|||||||
|
try:
|
||||||
|
from collections import OrderedDict
|
||||||
|
except ImportError:
|
||||||
|
# Support for Python 2.6
|
||||||
|
from ordereddict import OrderedDict
|
||||||
|
|
||||||
|
from py.log import Producer
|
||||||
|
from _pytest.runner import CollectReport
|
||||||
|
|
||||||
|
from xdist.slavemanage import parse_spec_config
|
||||||
|
from xdist.report import report_collection_diff
|
||||||
|
|
||||||
|
|
||||||
|
class LoadScopeScheduling:
|
||||||
|
"""Implement load scheduling across nodes, but grouping test by scope.
|
||||||
|
|
||||||
|
This distributes the tests collected across all nodes so each test is run
|
||||||
|
just once. All nodes collect and submit the list of tests and when all
|
||||||
|
collections are received it is verified they are identical collections.
|
||||||
|
Then the collection gets divided up in work units, grouped by test scope,
|
||||||
|
and those work units get submitted to nodes. Whenever a node finishes an
|
||||||
|
item, it calls ``.mark_test_complete()`` which will trigger the scheduler
|
||||||
|
to assign more work units if the number of pending tests for the node falls
|
||||||
|
below a low-watermark.
|
||||||
|
|
||||||
|
When created, ``numnodes`` defines how many nodes are expected to submit a
|
||||||
|
collection. This is used to know when all nodes have finished collection.
|
||||||
|
|
||||||
|
Attributes:
|
||||||
|
|
||||||
|
:numnodes: The expected number of nodes taking part. The actual number of
|
||||||
|
nodes will vary during the scheduler's lifetime as nodes are added by
|
||||||
|
the DSession as they are brought up and removed either because of a dead
|
||||||
|
node or normal shutdown. This number is primarily used to know when the
|
||||||
|
initial collection is completed.
|
||||||
|
|
||||||
|
:collection: The final list of tests collected by all nodes once it is
|
||||||
|
validated to be identical between all the nodes. It is initialised to
|
||||||
|
None until ``.schedule()`` is called.
|
||||||
|
|
||||||
|
:workqueue: Ordered dictionary that maps all available scopes with their
|
||||||
|
associated tests (nodeid). Nodeids are in turn associated with their
|
||||||
|
completion status. One entry of the workqueue is called a work unit.
|
||||||
|
In turn, a collection of work unit is called a workload.
|
||||||
|
|
||||||
|
::
|
||||||
|
|
||||||
|
workqueue = {
|
||||||
|
'<full>/<path>/<to>/test_module.py': {
|
||||||
|
'<full>/<path>/<to>/test_module.py::test_case1': False,
|
||||||
|
'<full>/<path>/<to>/test_module.py::test_case2': False,
|
||||||
|
(...)
|
||||||
|
},
|
||||||
|
(...)
|
||||||
|
}
|
||||||
|
|
||||||
|
:assigned_work: Ordered dictionary that maps worker nodes with their
|
||||||
|
assigned work units.
|
||||||
|
|
||||||
|
::
|
||||||
|
|
||||||
|
assigned_work = {
|
||||||
|
'<worker node A>': {
|
||||||
|
'<full>/<path>/<to>/test_module.py': {
|
||||||
|
'<full>/<path>/<to>/test_module.py::test_case1': False,
|
||||||
|
'<full>/<path>/<to>/test_module.py::test_case2': False,
|
||||||
|
(...)
|
||||||
|
},
|
||||||
|
(...)
|
||||||
|
},
|
||||||
|
(...)
|
||||||
|
}
|
||||||
|
|
||||||
|
:registered_collections: Ordered dictionary that maps worker nodes with
|
||||||
|
their collection of tests gathered during test discovery.
|
||||||
|
|
||||||
|
::
|
||||||
|
|
||||||
|
registered_collections = {
|
||||||
|
'<worker node A>': [
|
||||||
|
'<full>/<path>/<to>/test_module.py::test_case1',
|
||||||
|
'<full>/<path>/<to>/test_module.py::test_case2',
|
||||||
|
],
|
||||||
|
(...)
|
||||||
|
}
|
||||||
|
|
||||||
|
:log: A py.log.Producer instance.
|
||||||
|
|
||||||
|
:config: Config object, used for handling hooks.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, config, log=None):
|
||||||
|
self.numnodes = len(parse_spec_config(config))
|
||||||
|
self.collection = None
|
||||||
|
|
||||||
|
self.workqueue = OrderedDict()
|
||||||
|
self.assigned_work = OrderedDict()
|
||||||
|
self.registered_collections = OrderedDict()
|
||||||
|
|
||||||
|
if log is None:
|
||||||
|
self.log = Producer('loadscopesched')
|
||||||
|
else:
|
||||||
|
self.log = log.loadscopesched
|
||||||
|
|
||||||
|
self.config = config
|
||||||
|
|
||||||
|
@property
|
||||||
|
def nodes(self):
|
||||||
|
"""A list of all active nodes in the scheduler."""
|
||||||
|
return list(self.assigned_work.keys())
|
||||||
|
|
||||||
|
@property
|
||||||
|
def collection_is_completed(self):
|
||||||
|
"""Boolean indication initial test collection is complete.
|
||||||
|
|
||||||
|
This is a boolean indicating all initial participating nodes have
|
||||||
|
finished collection. The required number of initial nodes is defined
|
||||||
|
by ``.numnodes``.
|
||||||
|
"""
|
||||||
|
return len(self.registered_collections) >= self.numnodes
|
||||||
|
|
||||||
|
@property
|
||||||
|
def tests_finished(self):
|
||||||
|
"""Return True if all tests have been executed by the nodes."""
|
||||||
|
if not self.collection_is_completed:
|
||||||
|
return False
|
||||||
|
|
||||||
|
if self.workqueue:
|
||||||
|
return False
|
||||||
|
|
||||||
|
for assigned_unit in self.assigned_work.values():
|
||||||
|
if self._pending_of(assigned_unit) >= 2:
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
@property
|
||||||
|
def has_pending(self):
|
||||||
|
"""Return True if there are pending test items.
|
||||||
|
|
||||||
|
This indicates that collection has finished and nodes are still
|
||||||
|
processing test items, so this can be thought of as
|
||||||
|
"the scheduler is active".
|
||||||
|
"""
|
||||||
|
if self.workqueue:
|
||||||
|
return True
|
||||||
|
|
||||||
|
for assigned_unit in self.assigned_work.values():
|
||||||
|
if self._pending_of(assigned_unit) > 0:
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
def add_node(self, node):
|
||||||
|
"""Add a new node to the scheduler.
|
||||||
|
|
||||||
|
From now on the node will be assigned work units to be executed.
|
||||||
|
|
||||||
|
Called by the ``DSession.slave_slaveready`` hook when it successfully
|
||||||
|
bootstraps a new node.
|
||||||
|
"""
|
||||||
|
assert node not in self.assigned_work
|
||||||
|
self.assigned_work[node] = OrderedDict()
|
||||||
|
|
||||||
|
def remove_node(self, node):
|
||||||
|
"""Remove a node from the scheduler.
|
||||||
|
|
||||||
|
This should be called either when the node crashed or at shutdown time.
|
||||||
|
In the former case any pending items assigned to the node will be
|
||||||
|
re-scheduled.
|
||||||
|
|
||||||
|
Called by the hooks:
|
||||||
|
|
||||||
|
- ``DSession.slave_slavefinished``.
|
||||||
|
- ``DSession.slave_errordown``.
|
||||||
|
|
||||||
|
Return the item being executed while the node crashed or None if the
|
||||||
|
node has no more pending items.
|
||||||
|
"""
|
||||||
|
workload = self.assigned_work.pop(node)
|
||||||
|
if not self._pending_of(workload):
|
||||||
|
return None
|
||||||
|
|
||||||
|
# The node crashed, identify test that crashed
|
||||||
|
for work_unit in workload.values():
|
||||||
|
for nodeid, completed in work_unit.items():
|
||||||
|
if not completed:
|
||||||
|
crashitem = nodeid
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
continue
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
raise RuntimeError(
|
||||||
|
'Unable to identify crashitem on a workload with '
|
||||||
|
'pending items'
|
||||||
|
)
|
||||||
|
|
||||||
|
# Made uncompleted work unit available again
|
||||||
|
self.workqueue.update(workload)
|
||||||
|
|
||||||
|
for node in self.assigned_work:
|
||||||
|
self._reschedule(node)
|
||||||
|
|
||||||
|
return crashitem
|
||||||
|
|
||||||
|
def add_node_collection(self, node, collection):
|
||||||
|
"""Add the collected test items from a node.
|
||||||
|
|
||||||
|
The collection is stored in the ``.registered_collections`` dictionary.
|
||||||
|
|
||||||
|
Called by the hook:
|
||||||
|
|
||||||
|
- ``DSession.slave_collectionfinish``.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Check that add_node() was called on the node before
|
||||||
|
assert node in self.assigned_work
|
||||||
|
|
||||||
|
# A new node has been added later, perhaps an original one died.
|
||||||
|
if self.collection_is_completed:
|
||||||
|
|
||||||
|
# Assert that .schedule() should have been called by now
|
||||||
|
assert self.collection
|
||||||
|
|
||||||
|
# Check that the new collection matches the official collection
|
||||||
|
if collection != self.collection:
|
||||||
|
|
||||||
|
other_node = next(iter(self.registered_collections.keys()))
|
||||||
|
|
||||||
|
msg = report_collection_diff(
|
||||||
|
self.collection,
|
||||||
|
collection,
|
||||||
|
other_node.gateway.id,
|
||||||
|
node.gateway.id
|
||||||
|
)
|
||||||
|
self.log(msg)
|
||||||
|
return
|
||||||
|
|
||||||
|
self.registered_collections[node] = list(collection)
|
||||||
|
|
||||||
|
def mark_test_complete(self, node, item_index, duration=0):
|
||||||
|
"""Mark test item as completed by node.
|
||||||
|
|
||||||
|
Called by the hook:
|
||||||
|
|
||||||
|
- ``DSession.slave_testreport``.
|
||||||
|
"""
|
||||||
|
nodeid = self.registered_collections[node][item_index]
|
||||||
|
scope = self._split_scope(nodeid)
|
||||||
|
|
||||||
|
self.assigned_work[node][scope][nodeid] = True
|
||||||
|
self._reschedule(node)
|
||||||
|
|
||||||
|
def _assign_work_unit(self, node):
|
||||||
|
"""Assign a work unit to a node."""
|
||||||
|
assert self.workqueue
|
||||||
|
|
||||||
|
# Grab a unit of work
|
||||||
|
scope, work_unit = self.workqueue.popitem(last=False)
|
||||||
|
|
||||||
|
# Keep track of the assigned work
|
||||||
|
assigned_to_node = self.assigned_work.setdefault(
|
||||||
|
node, default=OrderedDict()
|
||||||
|
)
|
||||||
|
assigned_to_node[scope] = work_unit
|
||||||
|
|
||||||
|
# Ask the node to execute the workload
|
||||||
|
worker_collection = self.registered_collections[node]
|
||||||
|
nodeids_indexes = [
|
||||||
|
worker_collection.index(nodeid)
|
||||||
|
for nodeid, completed in work_unit.items()
|
||||||
|
if not completed
|
||||||
|
]
|
||||||
|
|
||||||
|
node.send_runtest_some(nodeids_indexes)
|
||||||
|
|
||||||
|
def _split_scope(self, nodeid):
|
||||||
|
"""Determine the scope (grouping) of a nodeid.
|
||||||
|
|
||||||
|
There are usually 3 cases for a nodeid::
|
||||||
|
|
||||||
|
example/loadsuite/test/test_beta.py::test_beta0
|
||||||
|
example/loadsuite/test/test_delta.py::Delta1::test_delta0
|
||||||
|
example/loadsuite/epsilon/__init__.py::epsilon.epsilon
|
||||||
|
|
||||||
|
#. Function in a test module.
|
||||||
|
#. Method of a class in a test module.
|
||||||
|
#. Doctest in a function in a package.
|
||||||
|
|
||||||
|
This function will group tests with the scope determined by splitting
|
||||||
|
the first ``::`` from the right. That is, classes will be grouped in a
|
||||||
|
single work unit, and functions from a test module will be grouped by
|
||||||
|
their module. In the above example, scopes will be::
|
||||||
|
|
||||||
|
example/loadsuite/test/test_beta.py
|
||||||
|
example/loadsuite/test/test_delta.py::Delta1
|
||||||
|
example/loadsuite/epsilon/__init__.py
|
||||||
|
"""
|
||||||
|
return nodeid.rsplit('::', 1)[0]
|
||||||
|
|
||||||
|
def _pending_of(self, workload):
|
||||||
|
"""Return the number of pending tests in a workload."""
|
||||||
|
pending = sum(
|
||||||
|
list(scope.values()).count(False)
|
||||||
|
for scope in workload.values()
|
||||||
|
)
|
||||||
|
return pending
|
||||||
|
|
||||||
|
def _reschedule(self, node):
|
||||||
|
"""Maybe schedule new items on the node.
|
||||||
|
|
||||||
|
If there are any globally pending work units left then this will check
|
||||||
|
if the given node should be given any more tests.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Do not add more work to a node shutting down
|
||||||
|
if node.shutting_down:
|
||||||
|
return
|
||||||
|
|
||||||
|
# Check that more work is available
|
||||||
|
if not self.workqueue:
|
||||||
|
return
|
||||||
|
|
||||||
|
self.log('Number of units waiting for node:', len(self.workqueue))
|
||||||
|
|
||||||
|
# Check that the node is almost depleted of work
|
||||||
|
# 2: Heuristic of minimum tests to enqueue more work
|
||||||
|
if self._pending_of(self.assigned_work[node]) > 2:
|
||||||
|
return
|
||||||
|
|
||||||
|
# Pop one unit of work and assign it
|
||||||
|
self._assign_work_unit(node)
|
||||||
|
|
||||||
|
def schedule(self):
|
||||||
|
"""Initiate distribution of the test collection.
|
||||||
|
|
||||||
|
Initiate scheduling of the items across the nodes. If this gets called
|
||||||
|
again later it behaves the same as calling ``._reschedule()`` on all
|
||||||
|
nodes so that newly added nodes will start to be used.
|
||||||
|
|
||||||
|
If ``.collection_is_completed`` is True, this is called by the hook:
|
||||||
|
|
||||||
|
- ``DSession.slave_collectionfinish``.
|
||||||
|
"""
|
||||||
|
assert self.collection_is_completed
|
||||||
|
|
||||||
|
# Initial distribution already happened, reschedule on all nodes
|
||||||
|
if self.collection is not None:
|
||||||
|
for node in self.nodes:
|
||||||
|
self._reschedule(node)
|
||||||
|
return
|
||||||
|
|
||||||
|
# Check that all nodes collected the same tests
|
||||||
|
if not self._check_nodes_have_same_collection():
|
||||||
|
self.log('**Different tests collected, aborting run**')
|
||||||
|
return
|
||||||
|
|
||||||
|
# Collections are identical, create the final list of items
|
||||||
|
self.collection = list(
|
||||||
|
next(iter(self.registered_collections.values()))
|
||||||
|
)
|
||||||
|
if not self.collection:
|
||||||
|
return
|
||||||
|
|
||||||
|
# Determine chunks of work (scopes)
|
||||||
|
for nodeid in self.collection:
|
||||||
|
scope = self._split_scope(nodeid)
|
||||||
|
work_unit = self.workqueue.setdefault(scope, default=OrderedDict())
|
||||||
|
work_unit[nodeid] = False
|
||||||
|
|
||||||
|
# Avoid having more workers than work
|
||||||
|
extra_nodes = len(self.nodes) - len(self.workqueue)
|
||||||
|
|
||||||
|
if extra_nodes > 0:
|
||||||
|
self.log('Shuting down {} nodes'.format(extra_nodes))
|
||||||
|
|
||||||
|
for _ in range(extra_nodes):
|
||||||
|
unused_node, assigned = self.assigned_work.popitem(last=True)
|
||||||
|
|
||||||
|
self.log('Shuting down unused node {}'.format(unused_node))
|
||||||
|
unused_node.shutdown()
|
||||||
|
|
||||||
|
# Assign initial workload
|
||||||
|
for node in self.nodes:
|
||||||
|
self._assign_work_unit(node)
|
||||||
|
|
||||||
|
# Initial distribution sent all tests, start node shutdown
|
||||||
|
if not self.workqueue:
|
||||||
|
for node in self.nodes:
|
||||||
|
node.shutdown()
|
||||||
|
|
||||||
|
def _check_nodes_have_same_collection(self):
|
||||||
|
"""Return True if all nodes have collected the same items.
|
||||||
|
|
||||||
|
If collections differ, this method returns False while logging
|
||||||
|
the collection differences and posting collection errors to
|
||||||
|
pytest_collectreport hook.
|
||||||
|
"""
|
||||||
|
node_collection_items = list(self.registered_collections.items())
|
||||||
|
first_node, col = node_collection_items[0]
|
||||||
|
same_collection = True
|
||||||
|
|
||||||
|
for node, collection in node_collection_items[1:]:
|
||||||
|
msg = report_collection_diff(
|
||||||
|
col,
|
||||||
|
collection,
|
||||||
|
first_node.gateway.id,
|
||||||
|
node.gateway.id,
|
||||||
|
)
|
||||||
|
if not msg:
|
||||||
|
continue
|
||||||
|
|
||||||
|
same_collection = False
|
||||||
|
self.log(msg)
|
||||||
|
|
||||||
|
if self.config is None:
|
||||||
|
continue
|
||||||
|
|
||||||
|
rep = CollectReport(
|
||||||
|
node.gateway.id,
|
||||||
|
'failed',
|
||||||
|
longrepr=msg,
|
||||||
|
result=[]
|
||||||
|
)
|
||||||
|
self.config.hook.pytest_collectreport(report=rep)
|
||||||
|
|
||||||
|
return same_collection
|
||||||
@@ -315,6 +315,10 @@ class SlaveController(object):
|
|||||||
self.notify_inproc(eventname, node=self, rep=rep)
|
self.notify_inproc(eventname, node=self, rep=rep)
|
||||||
elif eventname == "collectionfinish":
|
elif eventname == "collectionfinish":
|
||||||
self.notify_inproc(eventname, node=self, ids=kwargs['ids'])
|
self.notify_inproc(eventname, node=self, ids=kwargs['ids'])
|
||||||
|
elif eventname == "logwarning":
|
||||||
|
self.notify_inproc(eventname, message=kwargs['message'],
|
||||||
|
code=kwargs['code'], nodeid=kwargs['nodeid'],
|
||||||
|
fslocation=kwargs['nodeid'])
|
||||||
else:
|
else:
|
||||||
raise ValueError("unknown event: %s" % (eventname,))
|
raise ValueError("unknown event: %s" % (eventname,))
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
@@ -323,16 +327,20 @@ class SlaveController(object):
|
|||||||
except:
|
except:
|
||||||
excinfo = py.code.ExceptionInfo()
|
excinfo = py.code.ExceptionInfo()
|
||||||
py.builtin.print_("!" * 20, excinfo)
|
py.builtin.print_("!" * 20, excinfo)
|
||||||
self.config.pluginmanager.notify_exception(excinfo)
|
self.config.notify_exception(excinfo)
|
||||||
|
self.shutdown()
|
||||||
|
self.notify_inproc("errordown", node=self, error=excinfo)
|
||||||
|
|
||||||
|
|
||||||
def unserialize_report(name, reportdict):
|
def unserialize_report(name, reportdict):
|
||||||
def assembled_report(reportdict):
|
def assembled_report(reportdict):
|
||||||
from _pytest._code.code import (
|
from _pytest._code.code import (
|
||||||
|
ReprEntry,
|
||||||
|
ReprEntryNative,
|
||||||
ReprExceptionInfo,
|
ReprExceptionInfo,
|
||||||
ReprFileLocation,
|
ReprFileLocation,
|
||||||
ReprEntry,
|
|
||||||
ReprFuncArgs,
|
ReprFuncArgs,
|
||||||
|
ReprLocals,
|
||||||
ReprTraceback
|
ReprTraceback
|
||||||
)
|
)
|
||||||
if reportdict['longrepr']:
|
if reportdict['longrepr']:
|
||||||
@@ -342,30 +350,64 @@ def unserialize_report(name, reportdict):
|
|||||||
reprcrash = reportdict['longrepr']['reprcrash']
|
reprcrash = reportdict['longrepr']['reprcrash']
|
||||||
|
|
||||||
unserialized_entries = []
|
unserialized_entries = []
|
||||||
for entry in reprtraceback['reprentries']:
|
reprentry = None
|
||||||
reprfuncargs, reprfileloc = None, None
|
for entry_data in reprtraceback['reprentries']:
|
||||||
if entry['reprfuncargs']:
|
data = entry_data['data']
|
||||||
reprfuncargs = ReprFuncArgs(**entry['reprfuncargs'])
|
entry_type = entry_data['type']
|
||||||
if entry['reprfileloc']:
|
if entry_type == 'ReprEntry':
|
||||||
reprfileloc = ReprFileLocation(**entry['reprfileloc'])
|
reprfuncargs = None
|
||||||
|
reprfileloc = None
|
||||||
|
reprlocals = None
|
||||||
|
if data['reprfuncargs']:
|
||||||
|
reprfuncargs = ReprFuncArgs(
|
||||||
|
**data['reprfuncargs'])
|
||||||
|
if data['reprfileloc']:
|
||||||
|
reprfileloc = ReprFileLocation(
|
||||||
|
**data['reprfileloc'])
|
||||||
|
if data['reprlocals']:
|
||||||
|
reprlocals = ReprLocals(
|
||||||
|
data['reprlocals']['lines'])
|
||||||
|
|
||||||
reprentry = ReprEntry(
|
reprentry = ReprEntry(
|
||||||
lines=entry['lines'],
|
lines=data['lines'],
|
||||||
reprfuncargs=reprfuncargs,
|
reprfuncargs=reprfuncargs,
|
||||||
reprlocals=entry['reprlocals'],
|
reprlocals=reprlocals,
|
||||||
filelocrepr=reprfileloc,
|
filelocrepr=reprfileloc,
|
||||||
style=entry['style']
|
style=data['style']
|
||||||
)
|
)
|
||||||
|
elif entry_type == 'ReprEntryNative':
|
||||||
|
reprentry = ReprEntryNative(data['lines'])
|
||||||
|
else:
|
||||||
|
report_unserialization_failure(
|
||||||
|
entry_type, name, reportdict)
|
||||||
unserialized_entries.append(reprentry)
|
unserialized_entries.append(reprentry)
|
||||||
reprtraceback['reprentries'] = unserialized_entries
|
reprtraceback['reprentries'] = unserialized_entries
|
||||||
|
|
||||||
reportdict['longrepr'] = ReprExceptionInfo(
|
exception_info = ReprExceptionInfo(
|
||||||
reprtraceback=ReprTraceback(**reprtraceback),
|
reprtraceback=ReprTraceback(**reprtraceback),
|
||||||
reprcrash=ReprFileLocation(**reprcrash),
|
reprcrash=ReprFileLocation(**reprcrash),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
for section in reportdict['longrepr']['sections']:
|
||||||
|
exception_info.addsection(*section)
|
||||||
|
reportdict['longrepr'] = exception_info
|
||||||
return reportdict
|
return reportdict
|
||||||
|
|
||||||
if name == "testreport":
|
if name == "testreport":
|
||||||
return runner.TestReport(**assembled_report(reportdict))
|
return runner.TestReport(**assembled_report(reportdict))
|
||||||
elif name == "collectreport":
|
elif name == "collectreport":
|
||||||
return runner.CollectReport(**assembled_report(reportdict))
|
return runner.CollectReport(**assembled_report(reportdict))
|
||||||
|
|
||||||
|
|
||||||
|
def report_unserialization_failure(type_name, report_name, reportdict):
|
||||||
|
from pprint import pprint
|
||||||
|
url = 'https://github.com/pytest-dev/pytest-xdist/issues'
|
||||||
|
stream = py.io.TextIO()
|
||||||
|
pprint('-' * 100, stream=stream)
|
||||||
|
pprint('INTERNALERROR: Unknown entry type returned: %s' % type_name,
|
||||||
|
stream=stream)
|
||||||
|
pprint('report_name: %s' % report_name, stream=stream)
|
||||||
|
pprint(reportdict, stream=stream)
|
||||||
|
pprint('Please report this bug at %s' % url, stream=stream)
|
||||||
|
pprint('-' * 100, stream=stream)
|
||||||
|
assert 0, stream.getvalue()
|
||||||
|
|||||||
Reference in New Issue
Block a user