Compare commits
59 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9b2163f028 | ||
|
|
3f09e158be | ||
|
|
0d19e7f22b | ||
|
|
aedad85e35 | ||
|
|
a020c9509d | ||
|
|
efce50fe6a | ||
|
|
db1fb683cf | ||
|
|
28d60f94f3 | ||
|
|
ed9f25a0d2 | ||
|
|
cb8b161d36 | ||
|
|
cec33cca8a | ||
|
|
c6f2fdcc31 | ||
|
|
8b79d909ea | ||
|
|
2b0dc3f83a | ||
|
|
ed2db3d03a | ||
|
|
d3229af3da | ||
|
|
fad312fdb7 | ||
|
|
d4f977f3b7 | ||
|
|
5889e4c229 | ||
|
|
239065810e | ||
|
|
bf0645ad35 | ||
|
|
cf067a86d7 | ||
|
|
58f7291a99 | ||
|
|
2eb1002781 | ||
|
|
635d3d02cb | ||
|
|
adaa10f285 | ||
|
|
1cd7001647 | ||
|
|
95b660e26a | ||
|
|
7a5efcdb76 | ||
|
|
9e59d07947 | ||
|
|
3799caa4fc | ||
|
|
1e66af6389 | ||
|
|
7674f6b186 | ||
|
|
c83f73e19c | ||
|
|
c874872190 | ||
|
|
e4f36b18f3 | ||
|
|
0cdef59428 | ||
|
|
4bb06e3f74 | ||
|
|
2c9b0b8894 | ||
|
|
b464335c83 | ||
|
|
24b478446a | ||
|
|
d4d52dc933 | ||
|
|
e5c2347934 | ||
|
|
577418f28c | ||
|
|
5c46cdf62d | ||
|
|
493ba6cb1d | ||
|
|
d9bb158085 | ||
|
|
0175605c57 | ||
|
|
3ed405f22f | ||
|
|
7b9546b89b | ||
|
|
542111d272 | ||
|
|
2adf810e5e | ||
|
|
f8e138b986 | ||
|
|
469c8c50d0 | ||
|
|
79f1b6dab2 | ||
|
|
75e61d86b7 | ||
|
|
20a1b9ef11 | ||
|
|
a54f531701 | ||
|
|
4389843dcb |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -30,3 +30,4 @@ pytestdebug.log
|
|||||||
.tox/
|
.tox/
|
||||||
.cache/
|
.cache/
|
||||||
.eggs/
|
.eggs/
|
||||||
|
.idea/
|
||||||
|
|||||||
48
.travis.yml
48
.travis.yml
@@ -1,7 +1,17 @@
|
|||||||
sudo: false
|
sudo: false
|
||||||
language: python
|
language: python
|
||||||
|
|
||||||
|
notifications:
|
||||||
|
irc:
|
||||||
|
channels:
|
||||||
|
- 'chat.freenode.net#pytest'
|
||||||
|
on_success: change
|
||||||
|
on_failure: change
|
||||||
|
skip_join: true
|
||||||
|
email:
|
||||||
|
- pytest-commit@python.org
|
||||||
|
|
||||||
python:
|
python:
|
||||||
- '2.6'
|
|
||||||
- '2.7'
|
- '2.7'
|
||||||
- '3.4'
|
- '3.4'
|
||||||
- '3.5'
|
- '3.5'
|
||||||
@@ -10,32 +20,40 @@ env:
|
|||||||
- TOXENV=py-pytest30
|
- TOXENV=py-pytest30
|
||||||
- TOXENV=py-pytest31
|
- TOXENV=py-pytest31
|
||||||
- TOXENV=py-pytest32
|
- TOXENV=py-pytest32
|
||||||
|
- TOXENV=py-pytest33
|
||||||
|
|
||||||
install: pip install tox setuptools_scm
|
install: pip install tox setuptools_scm
|
||||||
matrix:
|
script: tox
|
||||||
|
|
||||||
|
jobs:
|
||||||
include:
|
include:
|
||||||
# note: please use "tox --listenvs" to populate the build matrix
|
- stage: test
|
||||||
|
# python x env above are already included into this stage
|
||||||
|
- python: "2.7"
|
||||||
|
env: TOXENV=py27-pytestmaster
|
||||||
|
- python: "2.7"
|
||||||
|
env: TOXENV=py27-pytestfeatures
|
||||||
|
- python: "3.6"
|
||||||
|
env: TOXENV=py36-pytestmaster
|
||||||
|
- python: "3.6"
|
||||||
|
env: TOXENV=py36-pytestfeatures
|
||||||
- python: "3.6"
|
- python: "3.6"
|
||||||
env: TOXENV=flakes
|
env: TOXENV=flakes
|
||||||
- python: "3.6"
|
- python: "3.6"
|
||||||
env: TOXENV=readme
|
env: TOXENV=readme
|
||||||
|
|
||||||
script: tox
|
- stage: deploy
|
||||||
notifications:
|
python: '3.6'
|
||||||
irc:
|
env:
|
||||||
channels:
|
install: pip install -U setuptools setuptools_scm
|
||||||
- chat.freenode.net#pytest
|
script: skip
|
||||||
on_success: change
|
deploy:
|
||||||
on_failure: change
|
|
||||||
skip_join: true
|
|
||||||
email:
|
|
||||||
- pytest-commit@python.org
|
|
||||||
deploy:
|
|
||||||
provider: pypi
|
provider: pypi
|
||||||
user: ronny
|
user: ronny
|
||||||
|
distributions: sdist bdist_wheel
|
||||||
skip_upload_docs: true
|
skip_upload_docs: true
|
||||||
password:
|
password:
|
||||||
secure: cxmSDho5d+PYKEM4ZCg8ms1P4lzhYkrw6fEOm2HtTcsuCyY6aZMSgImWAnEYbJHSkdzgcxlXK9UKJ9B0YenXmBCkAr7UjdnpNXNmkySr0sYzlH/sfqt/dDATCHFaRKxnkOSOVywaDYhT9n8YudbXI77pXwD12i/CeSSJDbHhsu0JYUfAcb+D6YjRYoA2SEGCnzSzg+gDDfwXZx4ZiODCGLVwieNp1klCg88YROUE1BaYYNuUOONvfXX8+TWowbCF6ChH1WL/bZ49OStEYQNuYxZQZr4yClIqu9VJbchrU8j860K9ott2kkGTgfB/dDrQB/XncBubyIX9ikzCQAmmBXWAI3eyvWLPDk2Jz7kW2l2RT7syct80tCq3JhvQ1qdwr5ap7siocTLgnBW0tF4tkHSTFN3510fkc43npnp6FThebESQpnI24vqpwJ9hI/kW5mYi014Og2E/cpCXnz2XO8iZPDbqAMQpDsqEQoyhfGNgPTGp4K30TxRtwZBI5hHhDKnnR16fXtRgt1gYPvz/peUQvvpOm4JzIzGXPzluuutpnCBy75v5+oiwT3YRrLL/Meims9FtDDXL3qQubAE/ezIOOpm0N5XXV8DxIom8EN71yq5ab1tqhM+tBX7owRjy4FR4If2Q8feBdmTuh26DIQt/y+qSG8VkB9Sw/JCjc7c=
|
secure: cxmSDho5d+PYKEM4ZCg8ms1P4lzhYkrw6fEOm2HtTcsuCyY6aZMSgImWAnEYbJHSkdzgcxlXK9UKJ9B0YenXmBCkAr7UjdnpNXNmkySr0sYzlH/sfqt/dDATCHFaRKxnkOSOVywaDYhT9n8YudbXI77pXwD12i/CeSSJDbHhsu0JYUfAcb+D6YjRYoA2SEGCnzSzg+gDDfwXZx4ZiODCGLVwieNp1klCg88YROUE1BaYYNuUOONvfXX8+TWowbCF6ChH1WL/bZ49OStEYQNuYxZQZr4yClIqu9VJbchrU8j860K9ott2kkGTgfB/dDrQB/XncBubyIX9ikzCQAmmBXWAI3eyvWLPDk2Jz7kW2l2RT7syct80tCq3JhvQ1qdwr5ap7siocTLgnBW0tF4tkHSTFN3510fkc43npnp6FThebESQpnI24vqpwJ9hI/kW5mYi014Og2E/cpCXnz2XO8iZPDbqAMQpDsqEQoyhfGNgPTGp4K30TxRtwZBI5hHhDKnnR16fXtRgt1gYPvz/peUQvvpOm4JzIzGXPzluuutpnCBy75v5+oiwT3YRrLL/Meims9FtDDXL3qQubAE/ezIOOpm0N5XXV8DxIom8EN71yq5ab1tqhM+tBX7owRjy4FR4If2Q8feBdmTuh26DIQt/y+qSG8VkB9Sw/JCjc7c=
|
||||||
on:
|
on:
|
||||||
tags: true
|
tags: true
|
||||||
distributions: sdist bdist_wheel
|
|
||||||
repo: pytest-dev/pytest-xdist
|
repo: pytest-dev/pytest-xdist
|
||||||
|
|||||||
@@ -1,3 +1,75 @@
|
|||||||
|
pytest-xdist 1.21.0 (2017-12-22)
|
||||||
|
================================
|
||||||
|
|
||||||
|
Deprecations and Removals
|
||||||
|
-------------------------
|
||||||
|
|
||||||
|
- Drop support for EOL Python 2.6. (`#259
|
||||||
|
<https://github.com/pytest-dev/pytest-xdist/issues/259>`_)
|
||||||
|
|
||||||
|
|
||||||
|
Features
|
||||||
|
--------
|
||||||
|
|
||||||
|
- New ``--dist=loadfile`` option which load-distributes test to workers grouped
|
||||||
|
by the file the tests live in. (`#242
|
||||||
|
<https://github.com/pytest-dev/pytest-xdist/issues/242>`_)
|
||||||
|
|
||||||
|
|
||||||
|
Bug Fixes
|
||||||
|
---------
|
||||||
|
|
||||||
|
- Fix accidental mutation of test report during serialization causing longrepr
|
||||||
|
string-ification to break. (`#241
|
||||||
|
<https://github.com/pytest-dev/pytest-xdist/issues/241>`_)
|
||||||
|
|
||||||
|
|
||||||
|
pytest-xdist 1.20.1 (2017-10-05)
|
||||||
|
================================
|
||||||
|
|
||||||
|
Bug Fixes
|
||||||
|
---------
|
||||||
|
|
||||||
|
- Fix hang when all worker nodes crash and restart limit is reached (`#45
|
||||||
|
<https://github.com/pytest-dev/pytest-xdist/issues/45>`_)
|
||||||
|
|
||||||
|
- Fix issue where the -n option would still run distributed tests when pytest
|
||||||
|
was run with the --collect-only option (`#5
|
||||||
|
<https://github.com/pytest-dev/pytest-xdist/issues/5>`_)
|
||||||
|
|
||||||
|
|
||||||
|
pytest-xdist 1.20.0 (2017-08-17)
|
||||||
|
================================
|
||||||
|
|
||||||
|
Features
|
||||||
|
--------
|
||||||
|
|
||||||
|
- ``xdist`` now supports tests to log results multiple times, improving
|
||||||
|
integration with plugins which require it like `pytest-rerunfailures
|
||||||
|
<https://github.com/gocept/pytest-rerunfailures>`_ and `flaky
|
||||||
|
<https://pypi.python.org/pypi/flaky>`_. (`#206 <https://github.com/pytest-
|
||||||
|
dev/pytest-xdist/issues/206>`_)
|
||||||
|
|
||||||
|
|
||||||
|
Bug Fixes
|
||||||
|
---------
|
||||||
|
|
||||||
|
- Fix issue where tests were being incorrectly identified if a worker crashed
|
||||||
|
during the ``teardown`` stage of the test. (`#124 <https://github.com/pytest-
|
||||||
|
dev/pytest-xdist/issues/124>`_)
|
||||||
|
|
||||||
|
|
||||||
|
pytest-xdist 1.19.1 (2017-08-10)
|
||||||
|
================================
|
||||||
|
|
||||||
|
Bug Fixes
|
||||||
|
---------
|
||||||
|
|
||||||
|
- Fix crash when transferring internal pytest warnings from workers to the
|
||||||
|
master node. (`#214 <https://github.com/pytest-dev/pytest-
|
||||||
|
xdist/issues/214>`_)
|
||||||
|
|
||||||
|
|
||||||
pytest-xdist 1.19.0 (2017-08-09)
|
pytest-xdist 1.19.0 (2017-08-09)
|
||||||
================================
|
================================
|
||||||
|
|
||||||
@@ -218,7 +290,7 @@ Improved Documentation
|
|||||||
in master. Thanks Aron Curzon.
|
in master. Thanks Aron Curzon.
|
||||||
|
|
||||||
- fix pytest issue419 by sending/receiving indices into the test
|
- fix pytest issue419 by sending/receiving indices into the test
|
||||||
collection instead of node ids (which are not neccessarily unique
|
collection instead of node ids (which are not necessarily unique
|
||||||
for functions parametrized with duplicate values)
|
for functions parametrized with duplicate values)
|
||||||
|
|
||||||
- send multiple "to test" indices in one network message to a slave
|
- send multiple "to test" indices in one network message to a slave
|
||||||
|
|||||||
26
README.rst
26
README.rst
@@ -1,15 +1,23 @@
|
|||||||
|
|
||||||
|
|
||||||
.. image:: http://img.shields.io/pypi/v/pytest-xdist.svg
|
.. image:: http://img.shields.io/pypi/v/pytest-xdist.svg
|
||||||
|
:alt: PyPI version
|
||||||
|
:target: https://pypi.python.org/pypi/pytest-xdist
|
||||||
|
|
||||||
|
.. image:: https://img.shields.io/pypi/pyversions/pytest-xdist.svg
|
||||||
|
:alt: Python versions
|
||||||
:target: https://pypi.python.org/pypi/pytest-xdist
|
:target: https://pypi.python.org/pypi/pytest-xdist
|
||||||
|
|
||||||
.. image:: https://anaconda.org/conda-forge/pytest-xdist/badges/version.svg
|
.. image:: https://anaconda.org/conda-forge/pytest-xdist/badges/version.svg
|
||||||
|
:alt: Anaconda version
|
||||||
:target: https://anaconda.org/conda-forge/pytest-xdist
|
:target: https://anaconda.org/conda-forge/pytest-xdist
|
||||||
|
|
||||||
.. image:: https://travis-ci.org/pytest-dev/pytest-xdist.svg?branch=master
|
.. image:: https://travis-ci.org/pytest-dev/pytest-xdist.svg?branch=master
|
||||||
|
:alt: Travis CI build status
|
||||||
:target: https://travis-ci.org/pytest-dev/pytest-xdist
|
:target: https://travis-ci.org/pytest-dev/pytest-xdist
|
||||||
|
|
||||||
.. image:: https://ci.appveyor.com/api/projects/status/56eq1a1avd4sdd7e/branch/master?svg=true
|
.. image:: https://ci.appveyor.com/api/projects/status/56eq1a1avd4sdd7e/branch/master?svg=true
|
||||||
|
:alt: AppVeyor build status
|
||||||
:target: https://ci.appveyor.com/project/pytestbot/pytest-xdist
|
:target: https://ci.appveyor.com/project/pytestbot/pytest-xdist
|
||||||
|
|
||||||
xdist: pytest distributed testing plugin
|
xdist: pytest distributed testing plugin
|
||||||
@@ -229,7 +237,7 @@ You can also add default environments like this:
|
|||||||
.. code-block:: ini
|
.. code-block:: ini
|
||||||
|
|
||||||
[pytest]
|
[pytest]
|
||||||
addopts = --tx ssh=myhost//python=python2.5 --tx ssh=myhost//python=python2.6
|
addopts = --tx ssh=myhost//python=python2.5 --tx ssh=myhost//python=python3.6
|
||||||
|
|
||||||
and then just type::
|
and then just type::
|
||||||
|
|
||||||
@@ -313,6 +321,22 @@ the same worker ``gw0``, while the test methods from classes ``TestHDF`` and
|
|||||||
Currently the groupings can't be customized, with grouping by class takes
|
Currently the groupings can't be customized, with grouping by class takes
|
||||||
priority over grouping by module.
|
priority over grouping by module.
|
||||||
|
|
||||||
|
Sending tests to the same worker based on their file
|
||||||
|
++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
|
||||||
|
*New in version 1.21.*
|
||||||
|
|
||||||
|
.. 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 tests to the same worker grouped by their filename by using the
|
||||||
|
``--dist=loadfile`` option, so tests of the same file are guaranteed to run
|
||||||
|
in the same worker.
|
||||||
|
|
||||||
|
Using the example in the previous section, all tests from ``test_container.py`` will
|
||||||
|
run in the same worker, as well as the tests in ``test_io.py``.
|
||||||
|
|
||||||
|
|
||||||
Specifying "rsync" dirs in an ini-file
|
Specifying "rsync" dirs in an ini-file
|
||||||
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
|||||||
15
appveyor.yml
15
appveyor.yml
@@ -1,18 +1,17 @@
|
|||||||
environment:
|
environment:
|
||||||
matrix:
|
matrix:
|
||||||
# note: please use "tox --listenvs" to populate the build matrix
|
# note: please use "tox --listenvs" to populate the build matrix
|
||||||
- TOXENV: "py26-pytest30"
|
- TOXENV: "py27-pytest33"
|
||||||
- TOXENV: "py27-pytest30"
|
- TOXENV: "py34-pytest33"
|
||||||
- TOXENV: "py34-pytest30"
|
- TOXENV: "py35-pytest33"
|
||||||
- TOXENV: "py35-pytest30"
|
- TOXENV: "py36-pytest33"
|
||||||
- TOXENV: "py36-pytest30"
|
- TOXENV: "py27-pytest33-pexpect"
|
||||||
- TOXENV: "py27-pytest30-pexpect"
|
- TOXENV: "py36-pytest33-pexpect"
|
||||||
- TOXENV: "py35-pytest30-pexpect"
|
|
||||||
- TOXENV: "flakes"
|
- TOXENV: "flakes"
|
||||||
- TOXENV: "readme"
|
- TOXENV: "readme"
|
||||||
|
|
||||||
install:
|
install:
|
||||||
- C:\Python35\python -m pip install tox setuptools_scm
|
- C:\Python35\python -m pip install -U tox setuptools_scm pip
|
||||||
|
|
||||||
build: false # Not a C# project, build stuff at the test step instead.
|
build: false # Not a C# project, build stuff at the test step instead.
|
||||||
|
|
||||||
|
|||||||
11
setup.py
11
setup.py
@@ -1,12 +1,7 @@
|
|||||||
from sys import version_info
|
|
||||||
|
|
||||||
from setuptools import setup, find_packages
|
from setuptools import setup, find_packages
|
||||||
|
|
||||||
install_requires = ['execnet>=1.1', 'pytest>=3.0.0', 'pytest-forked']
|
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",
|
||||||
@@ -27,6 +22,7 @@ setup(
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
zip_safe=False,
|
zip_safe=False,
|
||||||
|
python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*',
|
||||||
install_requires=install_requires,
|
install_requires=install_requires,
|
||||||
setup_requires=['setuptools_scm'],
|
setup_requires=['setuptools_scm'],
|
||||||
classifiers=[
|
classifiers=[
|
||||||
@@ -41,6 +37,11 @@ setup(
|
|||||||
'Topic :: Software Development :: Quality Assurance',
|
'Topic :: Software Development :: Quality Assurance',
|
||||||
'Topic :: Utilities',
|
'Topic :: Utilities',
|
||||||
'Programming Language :: Python',
|
'Programming Language :: Python',
|
||||||
|
'Programming Language :: Python :: 2',
|
||||||
|
'Programming Language :: Python :: 2.7',
|
||||||
'Programming Language :: Python :: 3',
|
'Programming Language :: Python :: 3',
|
||||||
|
'Programming Language :: Python :: 3.4',
|
||||||
|
'Programming Language :: Python :: 3.5',
|
||||||
|
'Programming Language :: Python :: 3.6',
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -262,6 +262,17 @@ class TestDistribution:
|
|||||||
child.close()
|
child.close()
|
||||||
# assert ret == 2
|
# assert ret == 2
|
||||||
|
|
||||||
|
def test_dist_with_collectonly(self, testdir):
|
||||||
|
p1 = testdir.makepyfile("""
|
||||||
|
def test_ok():
|
||||||
|
pass
|
||||||
|
""")
|
||||||
|
result = testdir.runpytest(p1, "-n1", "--collect-only")
|
||||||
|
assert result.ret == 0
|
||||||
|
result.stdout.fnmatch_lines([
|
||||||
|
"*collected 1 item*",
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
class TestDistEach:
|
class TestDistEach:
|
||||||
def test_simple(self, testdir):
|
def test_simple(self, testdir):
|
||||||
@@ -340,18 +351,28 @@ class TestTerminalReporting:
|
|||||||
])
|
])
|
||||||
|
|
||||||
@pytest.mark.parametrize('n', ['-n0', '-n1'])
|
@pytest.mark.parametrize('n', ['-n0', '-n1'])
|
||||||
def test_logwarning(self, testdir, n):
|
@pytest.mark.parametrize('warn_type', ['pytest', 'builtin'])
|
||||||
|
def test_logwarning(self, testdir, n, warn_type):
|
||||||
from pkg_resources import parse_version
|
from pkg_resources import parse_version
|
||||||
if parse_version(pytest.__version__) < parse_version('3.1'):
|
if parse_version(pytest.__version__) < parse_version('3.1'):
|
||||||
pytest.skip('pytest warnings requires >= 3.1')
|
pytest.skip('pytest warnings requires >= 3.1')
|
||||||
|
|
||||||
|
if warn_type == 'builtin':
|
||||||
|
warn_code = """warnings.warn(UserWarning('this is a warning'))"""
|
||||||
|
elif warn_type == 'pytest':
|
||||||
|
warn_code = """request.config.warn('', 'this is a warning',
|
||||||
|
fslocation=py.path.local())"""
|
||||||
|
else:
|
||||||
|
assert False
|
||||||
testdir.makepyfile("""
|
testdir.makepyfile("""
|
||||||
import warnings
|
import warnings, py
|
||||||
def test_func():
|
def test_func(request):
|
||||||
warnings.warn('this is a warning')
|
{warn_code}
|
||||||
""")
|
""".format(warn_code=warn_code))
|
||||||
result = testdir.runpytest(n)
|
result = testdir.runpytest(n)
|
||||||
result.stdout.fnmatch_lines([
|
result.stdout.fnmatch_lines([
|
||||||
"*this is a warning*",
|
"*this is a warning*",
|
||||||
|
"*1 passed, 1 warnings*",
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
@@ -461,18 +482,60 @@ def test_funcarg_teardown_failure(testdir):
|
|||||||
assert result.ret
|
assert result.ret
|
||||||
|
|
||||||
|
|
||||||
def test_crashing_item(testdir):
|
@pytest.mark.parametrize('when', ['setup', 'call', 'teardown'])
|
||||||
|
def test_crashing_item(testdir, when):
|
||||||
|
"""Ensure crashing item is correctly reported during all testing stages"""
|
||||||
|
code = dict(setup='', call='', teardown='')
|
||||||
|
code[when] = 'py.process.kill(os.getpid())'
|
||||||
p = testdir.makepyfile("""
|
p = testdir.makepyfile("""
|
||||||
import py
|
|
||||||
import os
|
import os
|
||||||
def test_crash():
|
import py
|
||||||
py.process.kill(os.getpid())
|
import pytest
|
||||||
def test_noncrash():
|
|
||||||
|
@pytest.fixture
|
||||||
|
def fix():
|
||||||
|
{setup}
|
||||||
|
yield
|
||||||
|
{teardown}
|
||||||
|
|
||||||
|
def test_crash(fix):
|
||||||
|
{call}
|
||||||
pass
|
pass
|
||||||
""")
|
|
||||||
|
def test_ok():
|
||||||
|
pass
|
||||||
|
""".format(**code))
|
||||||
|
passes = 2 if when == 'teardown' else 1
|
||||||
result = testdir.runpytest("-n2", p)
|
result = testdir.runpytest("-n2", p)
|
||||||
result.stdout.fnmatch_lines([
|
result.stdout.fnmatch_lines([
|
||||||
"*crashed*test_crash*", "*1 failed*1 passed*"
|
"*crashed*test_crash*",
|
||||||
|
"*1 failed*%d passed*" % passes,
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
|
def test_multiple_log_reports(testdir):
|
||||||
|
"""
|
||||||
|
Ensure that pytest-xdist supports plugins that emit multiple logreports
|
||||||
|
(#206).
|
||||||
|
Inspired by pytest-rerunfailures.
|
||||||
|
"""
|
||||||
|
testdir.makeconftest("""
|
||||||
|
from _pytest.runner import runtestprotocol
|
||||||
|
def pytest_runtest_protocol(item, nextitem):
|
||||||
|
item.ihook.pytest_runtest_logstart(nodeid=item.nodeid,
|
||||||
|
location=item.location)
|
||||||
|
reports = runtestprotocol(item, nextitem=nextitem)
|
||||||
|
for report in reports:
|
||||||
|
item.ihook.pytest_runtest_logreport(report=report)
|
||||||
|
return True
|
||||||
|
""")
|
||||||
|
testdir.makepyfile("""
|
||||||
|
def test():
|
||||||
|
pass
|
||||||
|
""")
|
||||||
|
result = testdir.runpytest("-n1")
|
||||||
|
result.stdout.fnmatch_lines([
|
||||||
|
"*2 passed*",
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
@@ -649,6 +712,17 @@ class TestNodeFailure:
|
|||||||
"*2 failed*2 passed*",
|
"*2 failed*2 passed*",
|
||||||
])
|
])
|
||||||
|
|
||||||
|
def test_max_slave_restart_die(self, testdir):
|
||||||
|
f = testdir.makepyfile("""
|
||||||
|
import os
|
||||||
|
os._exit(1)
|
||||||
|
""")
|
||||||
|
res = testdir.runpytest(f, '-n4', '--max-slave-restart=0')
|
||||||
|
res.stdout.fnmatch_lines([
|
||||||
|
"*Unexpectedly no active workers*",
|
||||||
|
"*INTERNALERROR*"
|
||||||
|
])
|
||||||
|
|
||||||
def test_disable_restart(self, testdir):
|
def test_disable_restart(self, testdir):
|
||||||
f = testdir.makepyfile("""
|
f = testdir.makepyfile("""
|
||||||
import os
|
import os
|
||||||
@@ -681,9 +755,9 @@ def test_worker_id_fixture(testdir, n):
|
|||||||
with open(fname) as f:
|
with open(fname) as f:
|
||||||
worker_ids.add(f.read().strip())
|
worker_ids.add(f.read().strip())
|
||||||
if n == 0:
|
if n == 0:
|
||||||
assert worker_ids == set(['master'])
|
assert worker_ids == {'master'}
|
||||||
else:
|
else:
|
||||||
assert worker_ids == set(['gw0', 'gw1'])
|
assert worker_ids == {'gw0', 'gw1'}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('tb',
|
@pytest.mark.parametrize('tb',
|
||||||
@@ -782,11 +856,72 @@ class TestLoadScope:
|
|||||||
'test_a.py::TestB', result.outlines) in ({'gw0': 10}, {'gw1': 10})
|
'test_a.py::TestB', result.outlines) in ({'gw0': 10}, {'gw1': 10})
|
||||||
|
|
||||||
|
|
||||||
|
class TestFileScope:
|
||||||
|
|
||||||
|
def test_by_module(self, testdir):
|
||||||
|
test_file = """
|
||||||
|
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
|
||||||
|
"""
|
||||||
|
testdir.makepyfile(
|
||||||
|
test_a=test_file,
|
||||||
|
test_b=test_file,
|
||||||
|
)
|
||||||
|
result = testdir.runpytest('-n2', '--dist=loadfile', '-v')
|
||||||
|
test_a_workers_and_test_count = get_workers_and_test_count_by_prefix(
|
||||||
|
'test_a.py::TestA', result.outlines)
|
||||||
|
test_b_workers_and_test_count = get_workers_and_test_count_by_prefix(
|
||||||
|
'test_b.py::TestB', result.outlines)
|
||||||
|
|
||||||
|
assert test_a_workers_and_test_count in ({'gw0': 10}, {'gw1': 0}) or \
|
||||||
|
test_a_workers_and_test_count in ({'gw0': 0}, {'gw1': 10})
|
||||||
|
assert test_b_workers_and_test_count in ({'gw0': 10}, {'gw1': 0}) or \
|
||||||
|
test_b_workers_and_test_count in ({'gw0': 0}, {'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=loadfile', '-v')
|
||||||
|
test_a_workers_and_test_count = get_workers_and_test_count_by_prefix(
|
||||||
|
'test_a.py::TestA', result.outlines)
|
||||||
|
test_b_workers_and_test_count = get_workers_and_test_count_by_prefix(
|
||||||
|
'test_a.py::TestB', result.outlines)
|
||||||
|
|
||||||
|
assert test_a_workers_and_test_count in ({'gw0': 10}, {'gw1': 0}) or \
|
||||||
|
test_a_workers_and_test_count in ({'gw0': 0}, {'gw1': 10})
|
||||||
|
assert test_b_workers_and_test_count in ({'gw0': 10}, {'gw1': 0}) or \
|
||||||
|
test_b_workers_and_test_count in ({'gw0': 0}, {'gw1': 10})
|
||||||
|
|
||||||
|
|
||||||
def parse_tests_and_workers_from_output(lines):
|
def parse_tests_and_workers_from_output(lines):
|
||||||
result = []
|
result = []
|
||||||
for line in lines:
|
for line in lines:
|
||||||
# example match: "[gw0] PASSED test_a.py::test[7]"
|
# example match: "[gw0] PASSED test_a.py::test[7]"
|
||||||
m = re.match(r'\[(gw\d)\]\s(.*?)\s(.*::.*)', line.strip())
|
m = re.match(r'''
|
||||||
|
\[(gw\d)\] # worker
|
||||||
|
\s*
|
||||||
|
(?:\[\s*\d+%\])? # progress indicator (pytest >=3.3)
|
||||||
|
\s(.*?) # status string ("PASSED")
|
||||||
|
\s(.*::.*) # nodeid
|
||||||
|
''', line.strip(), re.VERBOSE)
|
||||||
if m:
|
if m:
|
||||||
worker, status, nodeid = m.groups()
|
worker, status, nodeid = m.groups()
|
||||||
result.append((worker, status, nodeid))
|
result.append((worker, status, nodeid))
|
||||||
|
|||||||
@@ -20,13 +20,13 @@ pytest_plugins = "pytester"
|
|||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
def _divert_atexit(request, monkeypatch):
|
def _divert_atexit(request, monkeypatch):
|
||||||
import atexit
|
import atexit
|
||||||
l = []
|
finalizers = []
|
||||||
|
|
||||||
def finish():
|
def finish():
|
||||||
while l:
|
while finalizers:
|
||||||
l.pop()()
|
finalizers.pop()()
|
||||||
|
|
||||||
monkeypatch.setattr(atexit, "register", l.append)
|
monkeypatch.setattr(atexit, "register", finalizers.append)
|
||||||
request.addfinalizer(finish)
|
request.addfinalizer(finish)
|
||||||
|
|
||||||
|
|
||||||
@@ -34,7 +34,7 @@ def pytest_addoption(parser):
|
|||||||
parser.addoption('--gx',
|
parser.addoption('--gx',
|
||||||
action="append",
|
action="append",
|
||||||
dest="gspecs",
|
dest="gspecs",
|
||||||
help=("add a global test environment, XSpec-syntax. "))
|
help="add a global test environment, XSpec-syntax. ")
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ class TestLoadScheduling:
|
|||||||
sched.add_node(MockNode())
|
sched.add_node(MockNode())
|
||||||
sched.add_node(MockNode())
|
sched.add_node(MockNode())
|
||||||
node1, node2 = sched.nodes
|
node1, node2 = sched.nodes
|
||||||
col = ["xyz"] * (6)
|
col = ["xyz"] * 6
|
||||||
sched.add_node_collection(node1, col)
|
sched.add_node_collection(node1, col)
|
||||||
sched.add_node_collection(node2, col)
|
sched.add_node_collection(node2, col)
|
||||||
sched.schedule()
|
sched.schedule()
|
||||||
|
|||||||
@@ -83,10 +83,10 @@ class TestStatRecorder:
|
|||||||
tmp = tmpdir
|
tmp = tmpdir
|
||||||
sd = StatRecorder([tmp])
|
sd = StatRecorder([tmp])
|
||||||
|
|
||||||
l = [True, False]
|
ret_values = [True, False]
|
||||||
monkeypatch.setattr(StatRecorder, 'check', lambda self: l.pop())
|
monkeypatch.setattr(StatRecorder, 'check', lambda self: ret_values.pop())
|
||||||
sd.waitonchange(checkinterval=0.2)
|
sd.waitonchange(checkinterval=0.2)
|
||||||
assert not l
|
assert not ret_values
|
||||||
|
|
||||||
|
|
||||||
class TestRemoteControl:
|
class TestRemoteControl:
|
||||||
|
|||||||
@@ -44,6 +44,36 @@ def test_auto_detect_cpus(testdir, monkeypatch):
|
|||||||
assert config.getoption('numprocesses') == 99
|
assert config.getoption('numprocesses') == 99
|
||||||
|
|
||||||
|
|
||||||
|
def test_boxed_with_collect_only(testdir):
|
||||||
|
from xdist.plugin import pytest_cmdline_main as check_options
|
||||||
|
config = testdir.parseconfigure("-n1", "--boxed")
|
||||||
|
check_options(config)
|
||||||
|
assert config.option.forked
|
||||||
|
|
||||||
|
config = testdir.parseconfigure("-n1", "--collect-only")
|
||||||
|
check_options(config)
|
||||||
|
assert not config.option.forked
|
||||||
|
|
||||||
|
config = testdir.parseconfigure("-n1", "--boxed", "--collect-only")
|
||||||
|
check_options(config)
|
||||||
|
assert config.option.forked
|
||||||
|
|
||||||
|
|
||||||
|
def test_dsession_with_collect_only(testdir):
|
||||||
|
from xdist.plugin import pytest_cmdline_main as check_options
|
||||||
|
from xdist.plugin import pytest_configure as configure
|
||||||
|
|
||||||
|
config = testdir.parseconfigure("-n1")
|
||||||
|
check_options(config)
|
||||||
|
configure(config)
|
||||||
|
assert config.pluginmanager.hasplugin("dsession")
|
||||||
|
|
||||||
|
config = testdir.parseconfigure("-n1", "--collect-only")
|
||||||
|
check_options(config)
|
||||||
|
configure(config)
|
||||||
|
assert not config.pluginmanager.hasplugin("dsession")
|
||||||
|
|
||||||
|
|
||||||
class TestDistOptions:
|
class TestDistOptions:
|
||||||
def test_getxspecs(self, testdir):
|
def test_getxspecs(self, testdir):
|
||||||
config = testdir.parseconfigure("--tx=popen", "--tx", "ssh=xyz")
|
config = testdir.parseconfigure("--tx=popen", "--tx", "ssh=xyz")
|
||||||
|
|||||||
@@ -79,6 +79,21 @@ def test_remoteinitconfig(testdir):
|
|||||||
|
|
||||||
|
|
||||||
class TestReportSerialization:
|
class TestReportSerialization:
|
||||||
|
def test_xdist_longrepr_to_str_issue_241(self, testdir):
|
||||||
|
testdir.makepyfile("""
|
||||||
|
import os
|
||||||
|
def test_a(): assert False
|
||||||
|
def test_b(): pass
|
||||||
|
""")
|
||||||
|
testdir.makeconftest("""
|
||||||
|
def pytest_runtest_logreport(report):
|
||||||
|
print(report.longrepr)
|
||||||
|
""")
|
||||||
|
res = testdir.runpytest('-n1', '-s')
|
||||||
|
res.stdout.fnmatch_lines([
|
||||||
|
'*1 failed, 1 passed *'
|
||||||
|
])
|
||||||
|
|
||||||
def test_xdist_report_longrepr_reprcrash_130(self, testdir):
|
def test_xdist_report_longrepr_reprcrash_130(self, testdir):
|
||||||
reprec = testdir.inline_runsource("""
|
reprec = testdir.inline_runsource("""
|
||||||
import py
|
import py
|
||||||
@@ -107,8 +122,6 @@ class TestReportSerialization:
|
|||||||
assert rep.longrepr.reprtraceback.style \
|
assert rep.longrepr.reprtraceback.style \
|
||||||
== a.longrepr.reprtraceback.style
|
== a.longrepr.reprtraceback.style
|
||||||
assert rep.longrepr.sections == a.longrepr.sections
|
assert rep.longrepr.sections == a.longrepr.sections
|
||||||
assert rep.longrepr.reprtraceback.reprentries \
|
|
||||||
== a.longrepr.reprtraceback.reprentries
|
|
||||||
# Missing section attribute PR171
|
# Missing section attribute PR171
|
||||||
assert added_section in a.longrepr.sections
|
assert added_section in a.longrepr.sections
|
||||||
|
|
||||||
@@ -127,14 +140,15 @@ class TestReportSerialization:
|
|||||||
|
|
||||||
rep_entries = rep.longrepr.reprtraceback.reprentries
|
rep_entries = rep.longrepr.reprtraceback.reprentries
|
||||||
a_entries = a.longrepr.reprtraceback.reprentries
|
a_entries = a.longrepr.reprtraceback.reprentries
|
||||||
assert rep_entries == a_entries
|
|
||||||
for i in range(len(a_entries)):
|
for i in range(len(a_entries)):
|
||||||
assert isinstance(rep_entries[i], ReprEntry)
|
assert isinstance(rep_entries[i], ReprEntry)
|
||||||
assert rep_entries[i].lines == a_entries[i].lines
|
assert rep_entries[i].lines == a_entries[i].lines
|
||||||
assert rep_entries[i].localssep == a_entries[i].localssep
|
assert rep_entries[i].localssep == a_entries[i].localssep
|
||||||
assert rep_entries[i].reprfileloc == a_entries[i].reprfileloc
|
assert rep_entries[i].reprfileloc.lineno == a_entries[i].reprfileloc.lineno
|
||||||
assert rep_entries[i].reprfuncargs == a_entries[i].reprfuncargs
|
assert rep_entries[i].reprfileloc.message == a_entries[i].reprfileloc.message
|
||||||
assert rep_entries[i].reprlocals == a_entries[i].reprlocals
|
assert rep_entries[i].reprfileloc.path == a_entries[i].reprfileloc.path
|
||||||
|
assert rep_entries[i].reprfuncargs.args == a_entries[i].reprfuncargs.args
|
||||||
|
assert rep_entries[i].reprlocals.lines == a_entries[i].reprlocals.lines
|
||||||
assert rep_entries[i].style == a_entries[i].style
|
assert rep_entries[i].style == a_entries[i].style
|
||||||
|
|
||||||
def test_reprentries_serialization_196(self, testdir):
|
def test_reprentries_serialization_196(self, testdir):
|
||||||
@@ -152,7 +166,6 @@ class TestReportSerialization:
|
|||||||
|
|
||||||
rep_entries = rep.longrepr.reprtraceback.reprentries
|
rep_entries = rep.longrepr.reprtraceback.reprentries
|
||||||
a_entries = a.longrepr.reprtraceback.reprentries
|
a_entries = a.longrepr.reprtraceback.reprentries
|
||||||
assert rep_entries == a_entries
|
|
||||||
for i in range(len(a_entries)):
|
for i in range(len(a_entries)):
|
||||||
assert isinstance(rep_entries[i], ReprEntryNative)
|
assert isinstance(rep_entries[i], ReprEntryNative)
|
||||||
assert rep_entries[i].lines == a_entries[i].lines
|
assert rep_entries[i].lines == a_entries[i].lines
|
||||||
|
|||||||
@@ -50,10 +50,10 @@ class TestNodeManagerPopen:
|
|||||||
assert gm.specs[0].chdir is None
|
assert gm.specs[0].chdir is None
|
||||||
|
|
||||||
def test_default_chdir(self, config):
|
def test_default_chdir(self, config):
|
||||||
l = ["ssh=noco", "socket=xyz"]
|
specs = ["ssh=noco", "socket=xyz"]
|
||||||
for spec in NodeManager(config, l).specs:
|
for spec in NodeManager(config, specs).specs:
|
||||||
assert spec.chdir == "pyexecnetcache"
|
assert spec.chdir == "pyexecnetcache"
|
||||||
for spec in NodeManager(config, l, defaultchdir="abc").specs:
|
for spec in NodeManager(config, specs, defaultchdir="abc").specs:
|
||||||
assert spec.chdir == "abc"
|
assert spec.chdir == "abc"
|
||||||
|
|
||||||
def test_popen_makegateway_events(self, config, hookrecorder,
|
def test_popen_makegateway_events(self, config, hookrecorder,
|
||||||
@@ -89,10 +89,10 @@ class TestNodeManagerPopen:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
gw.remote_exec = pseudoexec
|
gw.remote_exec = pseudoexec
|
||||||
l = []
|
notifications = []
|
||||||
for gw in hm.group:
|
for gw in hm.group:
|
||||||
hm.rsync(gw, source, notify=lambda *args: l.append(args))
|
hm.rsync(gw, source, notify=lambda *args: notifications.append(args))
|
||||||
assert not l
|
assert not notifications
|
||||||
hm.teardown_nodes()
|
hm.teardown_nodes()
|
||||||
assert not len(hm.group)
|
assert not len(hm.group)
|
||||||
assert "sys.path.insert" in gw.remote_exec.args[0]
|
assert "sys.path.insert" in gw.remote_exec.args[0]
|
||||||
@@ -102,11 +102,11 @@ class TestNodeManagerPopen:
|
|||||||
hm = NodeManager(config, ["popen//chdir=%s" % dest] * 1)
|
hm = NodeManager(config, ["popen//chdir=%s" % dest] * 1)
|
||||||
hm.setup_nodes(None)
|
hm.setup_nodes(None)
|
||||||
source.ensure("dir1", "dir2", "hello")
|
source.ensure("dir1", "dir2", "hello")
|
||||||
l = []
|
notifications = []
|
||||||
for gw in hm.group:
|
for gw in hm.group:
|
||||||
hm.rsync(gw, source, notify=lambda *args: l.append(args))
|
hm.rsync(gw, source, notify=lambda *args: notifications.append(args))
|
||||||
assert len(l) == 1
|
assert len(notifications) == 1
|
||||||
assert l[0] == ("rsyncrootready", hm.group['gw0'].spec, source)
|
assert notifications[0] == ("rsyncrootready", hm.group['gw0'].spec, source)
|
||||||
hm.teardown_nodes()
|
hm.teardown_nodes()
|
||||||
dest = dest.join(source.basename)
|
dest = dest.join(source.basename)
|
||||||
assert dest.join("dir1").check()
|
assert dest.join("dir1").check()
|
||||||
@@ -137,9 +137,9 @@ class TestHRSync:
|
|||||||
source.ensure(".somedotfile", "moreentries")
|
source.ensure(".somedotfile", "moreentries")
|
||||||
source.ensure("somedir", "editfile~")
|
source.ensure("somedir", "editfile~")
|
||||||
syncer = HostRSync(source, ignores=NodeManager.DEFAULT_IGNORES)
|
syncer = HostRSync(source, ignores=NodeManager.DEFAULT_IGNORES)
|
||||||
l = list(source.visit(rec=syncer.filter, fil=syncer.filter))
|
files = list(source.visit(rec=syncer.filter, fil=syncer.filter))
|
||||||
assert len(l) == 3
|
assert len(files) == 3
|
||||||
basenames = [x.basename for x in l]
|
basenames = [x.basename for x in files]
|
||||||
assert 'dir' in basenames
|
assert 'dir' in basenames
|
||||||
assert 'file.txt' in basenames
|
assert 'file.txt' in basenames
|
||||||
assert 'somedir' in basenames
|
assert 'somedir' in basenames
|
||||||
|
|||||||
8
tox.ini
8
tox.ini
@@ -1,8 +1,9 @@
|
|||||||
[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,31,32}
|
py{27,34,35,36}-pytest{30,31,32,33}
|
||||||
py{27,36}-pytest{30,31,32}-pexpect
|
py{27,36}-pytest{30,31,32,33}-pexpect
|
||||||
|
py{27,36}-pytest{master,features}
|
||||||
flakes
|
flakes
|
||||||
readme
|
readme
|
||||||
|
|
||||||
@@ -17,6 +18,9 @@ deps =
|
|||||||
pytest30: pytest~=3.0.5
|
pytest30: pytest~=3.0.5
|
||||||
pytest31: pytest~=3.1.0
|
pytest31: pytest~=3.1.0
|
||||||
pytest32: pytest~=3.2.0
|
pytest32: pytest~=3.2.0
|
||||||
|
pytest33: pytest~=3.3.0
|
||||||
|
pytestmaster: git+https://github.com/pytest-dev/pytest.git@master
|
||||||
|
pytestfeatures: git+https://github.com/pytest-dev/pytest.git@features
|
||||||
pexpect: pexpect
|
pexpect: pexpect
|
||||||
platform=
|
platform=
|
||||||
pexpect: linux|darwin
|
pexpect: linux|darwin
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ from xdist.scheduler import (
|
|||||||
EachScheduling,
|
EachScheduling,
|
||||||
LoadScheduling,
|
LoadScheduling,
|
||||||
LoadScopeScheduling,
|
LoadScopeScheduling,
|
||||||
|
LoadFileScheduling,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -99,6 +100,7 @@ class DSession:
|
|||||||
'each': EachScheduling,
|
'each': EachScheduling,
|
||||||
'load': LoadScheduling,
|
'load': LoadScheduling,
|
||||||
'loadscope': LoadScopeScheduling,
|
'loadscope': LoadScopeScheduling,
|
||||||
|
'loadfile': LoadFileScheduling,
|
||||||
}
|
}
|
||||||
return schedulers[dist](config, log)
|
return schedulers[dist](config, log)
|
||||||
|
|
||||||
@@ -120,6 +122,10 @@ class DSession:
|
|||||||
def loop_once(self):
|
def loop_once(self):
|
||||||
"""Process one callback from one of the slaves."""
|
"""Process one callback from one of the slaves."""
|
||||||
while 1:
|
while 1:
|
||||||
|
if not self._active_nodes:
|
||||||
|
# If everything has died stop looping
|
||||||
|
self.triggershutdown()
|
||||||
|
raise RuntimeError("Unexpectedly no active workers available")
|
||||||
try:
|
try:
|
||||||
eventcall = self.queue.get(timeout=2.0)
|
eventcall = self.queue.get(timeout=2.0)
|
||||||
break
|
break
|
||||||
@@ -230,18 +236,19 @@ class DSession:
|
|||||||
nodeid=nodeid, location=location)
|
nodeid=nodeid, location=location)
|
||||||
|
|
||||||
def slave_testreport(self, node, rep):
|
def slave_testreport(self, node, rep):
|
||||||
"""Emitted when a node calls the pytest_runtest_logreport hook.
|
"""Emitted when a node calls the pytest_runtest_logreport hook."""
|
||||||
|
|
||||||
If the node indicates it is finished with a test item, remove
|
|
||||||
the item from the pending list in the scheduler.
|
|
||||||
"""
|
|
||||||
if rep.when == "call" or (rep.when == "setup" and not rep.passed):
|
|
||||||
self.sched.mark_test_complete(node, rep.item_index, rep.duration)
|
|
||||||
# self.report_line("testreport %s: %s" %(rep.id, rep.status))
|
|
||||||
rep.node = node
|
rep.node = node
|
||||||
self.config.hook.pytest_runtest_logreport(report=rep)
|
self.config.hook.pytest_runtest_logreport(report=rep)
|
||||||
self._handlefailures(rep)
|
self._handlefailures(rep)
|
||||||
|
|
||||||
|
def slave_runtest_protocol_complete(self, node, item_index, duration):
|
||||||
|
"""
|
||||||
|
Emitted when a node fires the 'runtest_protocol_complete' event,
|
||||||
|
signalling that a test has completed the runtestprotocol and should be
|
||||||
|
removed from the pending list in the scheduler.
|
||||||
|
"""
|
||||||
|
self.sched.mark_test_complete(node, item_index, duration)
|
||||||
|
|
||||||
def slave_collectreport(self, node, rep):
|
def slave_collectreport(self, node, rep):
|
||||||
"""Emitted when a node calls the pytest_collectreport hook."""
|
"""Emitted when a node calls the pytest_collectreport hook."""
|
||||||
if rep.failed:
|
if rep.failed:
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ def pytest_addoption(parser):
|
|||||||
"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=['each', 'load', 'loadscope', 'no'],
|
action="store", choices=['each', 'load', 'loadscope', 'loadfile', '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 all available environments.\n\n"
|
"each: send each test to all available environments.\n\n"
|
||||||
@@ -39,6 +39,8 @@ def pytest_addoption(parser):
|
|||||||
" available environment.\n\n"
|
" available environment.\n\n"
|
||||||
"loadscope: load balance by sending pending groups of tests in"
|
"loadscope: load balance by sending pending groups of tests in"
|
||||||
" the same scope to any available environment.\n\n"
|
" the same scope to any available environment.\n\n"
|
||||||
|
"loadfile: load balance by sending test grouped by file"
|
||||||
|
" 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=[],
|
||||||
@@ -91,7 +93,7 @@ def pytest_addhooks(pluginmanager):
|
|||||||
|
|
||||||
@pytest.mark.trylast
|
@pytest.mark.trylast
|
||||||
def pytest_configure(config):
|
def pytest_configure(config):
|
||||||
if config.getoption("dist") != "no":
|
if config.getoption("dist") != "no" and not config.getvalue("collectonly"):
|
||||||
from xdist.dsession import DSession
|
from xdist.dsession import DSession
|
||||||
session = DSession(config)
|
session = DSession(config)
|
||||||
config.pluginmanager.register(session, "dsession")
|
config.pluginmanager.register(session, "dsession")
|
||||||
@@ -115,7 +117,7 @@ def pytest_cmdline_main(config):
|
|||||||
if val("dist") != "no":
|
if val("dist") != "no":
|
||||||
if usepdb:
|
if usepdb:
|
||||||
raise pytest.UsageError(
|
raise pytest.UsageError(
|
||||||
"--pdb incompatible with distributing tests.")
|
"--pdb is incompatible with distributing tests; try using -n0.") # noqa: E501
|
||||||
|
|
||||||
# -------------------------------------------------------------------------
|
# -------------------------------------------------------------------------
|
||||||
# fixtures
|
# fixtures
|
||||||
@@ -124,6 +126,9 @@ def pytest_cmdline_main(config):
|
|||||||
|
|
||||||
@pytest.fixture(scope="session")
|
@pytest.fixture(scope="session")
|
||||||
def worker_id(request):
|
def worker_id(request):
|
||||||
|
"""Return the id of the current worker ('gw0', 'gw1', etc) or 'master'
|
||||||
|
if running on the master node.
|
||||||
|
"""
|
||||||
if hasattr(request.config, 'slaveinput'):
|
if hasattr(request.config, 'slaveinput'):
|
||||||
return request.config.slaveinput['slaveid']
|
return request.config.slaveinput['slaveid']
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
import time
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
@@ -59,23 +60,29 @@ class SlaveInteractor:
|
|||||||
self.log("items to run:", torun)
|
self.log("items to run:", torun)
|
||||||
# only run if we have an item and a next item
|
# only run if we have an item and a next item
|
||||||
while len(torun) >= 2:
|
while len(torun) >= 2:
|
||||||
self.run_tests(torun)
|
self.run_one_test(torun)
|
||||||
if name == "shutdown":
|
if name == "shutdown":
|
||||||
if torun:
|
if torun:
|
||||||
self.run_tests(torun)
|
self.run_one_test(torun)
|
||||||
break
|
break
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def run_tests(self, torun):
|
def run_one_test(self, torun):
|
||||||
items = self.session.items
|
items = self.session.items
|
||||||
self.item_index = torun.pop(0)
|
self.item_index = torun.pop(0)
|
||||||
|
item = items[self.item_index]
|
||||||
if torun:
|
if torun:
|
||||||
nextitem = items[torun[0]]
|
nextitem = items[torun[0]]
|
||||||
else:
|
else:
|
||||||
nextitem = None
|
nextitem = None
|
||||||
|
|
||||||
|
start = time.time()
|
||||||
self.config.hook.pytest_runtest_protocol(
|
self.config.hook.pytest_runtest_protocol(
|
||||||
item=items[self.item_index],
|
item=item,
|
||||||
nextitem=nextitem)
|
nextitem=nextitem)
|
||||||
|
duration = time.time() - start
|
||||||
|
self.sendevent("runtest_protocol_complete", item_index=self.item_index,
|
||||||
|
duration=duration)
|
||||||
|
|
||||||
def pytest_collection_finish(self, session):
|
def pytest_collection_finish(self, session):
|
||||||
self.sendevent(
|
self.sendevent(
|
||||||
@@ -99,23 +106,23 @@ class SlaveInteractor:
|
|||||||
|
|
||||||
def pytest_logwarning(self, message, code, nodeid, fslocation):
|
def pytest_logwarning(self, message, code, nodeid, fslocation):
|
||||||
self.sendevent("logwarning", message=message, code=code, nodeid=nodeid,
|
self.sendevent("logwarning", message=message, code=code, nodeid=nodeid,
|
||||||
fslocation=fslocation)
|
fslocation=str(fslocation))
|
||||||
|
|
||||||
|
|
||||||
def serialize_report(rep):
|
def serialize_report(rep):
|
||||||
def disassembled_report(rep):
|
def disassembled_report(rep):
|
||||||
reprtraceback = rep.longrepr.reprtraceback.__dict__
|
reprtraceback = rep.longrepr.reprtraceback.__dict__.copy()
|
||||||
reprcrash = rep.longrepr.reprcrash.__dict__
|
reprcrash = rep.longrepr.reprcrash.__dict__.copy()
|
||||||
|
|
||||||
new_entries = []
|
new_entries = []
|
||||||
for entry in reprtraceback['reprentries']:
|
for entry in reprtraceback['reprentries']:
|
||||||
entry_data = {
|
entry_data = {
|
||||||
'type': type(entry).__name__,
|
'type': type(entry).__name__,
|
||||||
'data': entry.__dict__,
|
'data': entry.__dict__.copy(),
|
||||||
}
|
}
|
||||||
for key, value in entry_data['data'].items():
|
for key, value in entry_data['data'].items():
|
||||||
if hasattr(value, '__dict__'):
|
if hasattr(value, '__dict__'):
|
||||||
entry_data['data'][key] = value.__dict__
|
entry_data['data'][key] = value.__dict__.copy()
|
||||||
new_entries.append(entry_data)
|
new_entries.append(entry_data)
|
||||||
|
|
||||||
reprtraceback['reprentries'] = new_entries
|
reprtraceback['reprentries'] = new_entries
|
||||||
@@ -171,10 +178,6 @@ def remote_initconfig(option_dict, args):
|
|||||||
|
|
||||||
if __name__ == '__channelexec__':
|
if __name__ == '__channelexec__':
|
||||||
channel = channel # noqa
|
channel = channel # noqa
|
||||||
# python3.2 is not concurrent import safe, so let's play it safe
|
|
||||||
# https://bitbucket.org/hpk42/pytest/issue/347/pytest-xdist-and-python-32
|
|
||||||
if sys.version_info[:2] == (3, 2):
|
|
||||||
os.environ["PYTHONDONTWRITEBYTECODE"] = "1"
|
|
||||||
slaveinput, args, option_dict = channel.receive()
|
slaveinput, args, option_dict = channel.receive()
|
||||||
importpath = os.getcwd()
|
importpath = os.getcwd()
|
||||||
sys.path.insert(0, importpath) # XXX only for remote situations
|
sys.path.insert(0, importpath) # XXX only for remote situations
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
from xdist.scheduler.each import EachScheduling # noqa
|
from xdist.scheduler.each import EachScheduling # noqa
|
||||||
from xdist.scheduler.load import LoadScheduling # noqa
|
from xdist.scheduler.load import LoadScheduling # noqa
|
||||||
from xdist.scheduler.loadscope import LoadScopeScheduling # noqa
|
from xdist.scheduler.loadscope import LoadScopeScheduling # noqa
|
||||||
|
from xdist.scheduler.filescope import LoadFileScheduling # noqa
|
||||||
|
|||||||
52
xdist/scheduler/filescope.py
Normal file
52
xdist/scheduler/filescope.py
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
from . import LoadScopeScheduling
|
||||||
|
from py.log import Producer
|
||||||
|
|
||||||
|
|
||||||
|
class LoadFileScheduling(LoadScopeScheduling):
|
||||||
|
"""Implement load scheduling across nodes, but grouping test test file.
|
||||||
|
|
||||||
|
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 file,
|
||||||
|
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.
|
||||||
|
|
||||||
|
This class behaves very much like LoadScopeScheduling, but with a file-level scope.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init(self, config, log=None):
|
||||||
|
super(LoadFileScheduling, self).__init__(config, log)
|
||||||
|
if log is None:
|
||||||
|
self.log = Producer('loadfilesched')
|
||||||
|
else:
|
||||||
|
self.log = log.loadfilesched
|
||||||
|
|
||||||
|
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 left. That is, test will be grouped in a
|
||||||
|
single work unit when they reside in the same file.
|
||||||
|
In the above example, scopes will be::
|
||||||
|
|
||||||
|
example/loadsuite/test/test_beta.py
|
||||||
|
example/loadsuite/test/test_delta.py
|
||||||
|
example/loadsuite/epsilon/__init__.py
|
||||||
|
"""
|
||||||
|
return nodeid.split('::', 1)[0]
|
||||||
@@ -1,14 +1,9 @@
|
|||||||
try:
|
from collections import OrderedDict
|
||||||
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 _pytest.runner import CollectReport
|
||||||
|
from py.log import Producer
|
||||||
from xdist.slavemanage import parse_spec_config
|
|
||||||
from xdist.report import report_collection_diff
|
from xdist.report import report_collection_diff
|
||||||
|
from xdist.slavemanage import parse_spec_config
|
||||||
|
|
||||||
|
|
||||||
class LoadScopeScheduling:
|
class LoadScopeScheduling:
|
||||||
@@ -373,12 +368,12 @@ class LoadScopeScheduling:
|
|||||||
extra_nodes = len(self.nodes) - len(self.workqueue)
|
extra_nodes = len(self.nodes) - len(self.workqueue)
|
||||||
|
|
||||||
if extra_nodes > 0:
|
if extra_nodes > 0:
|
||||||
self.log('Shuting down {} nodes'.format(extra_nodes))
|
self.log('Shuting down {0} nodes'.format(extra_nodes))
|
||||||
|
|
||||||
for _ in range(extra_nodes):
|
for _ in range(extra_nodes):
|
||||||
unused_node, assigned = self.assigned_work.popitem(last=True)
|
unused_node, assigned = self.assigned_work.popitem(last=True)
|
||||||
|
|
||||||
self.log('Shuting down unused node {}'.format(unused_node))
|
self.log('Shuting down unused node {0}'.format(unused_node))
|
||||||
unused_node.shutdown()
|
unused_node.shutdown()
|
||||||
|
|
||||||
# Assign initial workload
|
# Assign initial workload
|
||||||
|
|||||||
@@ -186,7 +186,7 @@ class HostRSync(execnet.RSync):
|
|||||||
def make_reltoroot(roots, args):
|
def make_reltoroot(roots, args):
|
||||||
# XXX introduce/use public API for splitting py.test args
|
# XXX introduce/use public API for splitting py.test args
|
||||||
splitcode = "::"
|
splitcode = "::"
|
||||||
l = []
|
result = []
|
||||||
for arg in args:
|
for arg in args:
|
||||||
parts = arg.split(splitcode)
|
parts = arg.split(splitcode)
|
||||||
fspath = py.path.local(parts[0])
|
fspath = py.path.local(parts[0])
|
||||||
@@ -197,8 +197,8 @@ def make_reltoroot(roots, args):
|
|||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
raise ValueError("arg %s not relative to an rsync root" % (arg,))
|
raise ValueError("arg %s not relative to an rsync root" % (arg,))
|
||||||
l.append(splitcode.join(parts))
|
result.append(splitcode.join(parts))
|
||||||
return l
|
return result
|
||||||
|
|
||||||
|
|
||||||
class SlaveController(object):
|
class SlaveController(object):
|
||||||
@@ -315,6 +315,8 @@ 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 == "runtest_protocol_complete":
|
||||||
|
self.notify_inproc(eventname, node=self, **kwargs)
|
||||||
elif eventname == "logwarning":
|
elif eventname == "logwarning":
|
||||||
self.notify_inproc(eventname, message=kwargs['message'],
|
self.notify_inproc(eventname, message=kwargs['message'],
|
||||||
code=kwargs['code'], nodeid=kwargs['nodeid'],
|
code=kwargs['code'], nodeid=kwargs['nodeid'],
|
||||||
@@ -324,7 +326,7 @@ class SlaveController(object):
|
|||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
# should not land in receiver-thread
|
# should not land in receiver-thread
|
||||||
raise
|
raise
|
||||||
except:
|
except: # noqa
|
||||||
excinfo = py.code.ExceptionInfo()
|
excinfo = py.code.ExceptionInfo()
|
||||||
py.builtin.print_("!" * 20, excinfo)
|
py.builtin.print_("!" * 20, excinfo)
|
||||||
self.config.notify_exception(excinfo)
|
self.config.notify_exception(excinfo)
|
||||||
@@ -344,7 +346,7 @@ def unserialize_report(name, reportdict):
|
|||||||
ReprTraceback
|
ReprTraceback
|
||||||
)
|
)
|
||||||
if reportdict['longrepr']:
|
if reportdict['longrepr']:
|
||||||
if 'reprcrash' and 'reprtraceback' in reportdict['longrepr']:
|
if 'reprcrash' in reportdict['longrepr'] and 'reprtraceback' in reportdict['longrepr']:
|
||||||
|
|
||||||
reprtraceback = reportdict['longrepr']['reprtraceback']
|
reprtraceback = reportdict['longrepr']['reprtraceback']
|
||||||
reprcrash = reportdict['longrepr']['reprcrash']
|
reprcrash = reportdict['longrepr']['reprcrash']
|
||||||
|
|||||||
Reference in New Issue
Block a user