Compare commits

..

7 Commits
1.11 ... 1.12

Author SHA1 Message Date
holger krekel
2ea07f73a7 finalize 1.12 version, some more adaptation for pytest versions, streamlining tox.ini 2015-05-06 13:41:39 +02:00
holger krekel
faf2e0861f streamline tests so that they work wit pytest-2.8 2015-05-06 13:34:33 +02:00
holger krekel
eb53a5f8a0 Added tag 1.11 for changeset 220f6e46eb71 2015-04-16 08:48:06 +02:00
Anatoly Bubenkov
5da798f01f README.txt edited online with Bitbucket 2015-03-01 14:45:15 +00:00
holger krekel
94a7723ba8 fix link to pytest-xdist repository 2015-02-27 12:19:16 +01:00
holger krekel
87be3b7582 (added changelog) fix issue594: properly report errors when the test collection
is random.  Thanks Bruno Oliveira.
2014-09-24 13:43:57 +02:00
Bruno Oliveira
d84f1f08d8 fix issue 594: xdist is not executing tests parametrized with random values
Now xdist properly reports the collection errors instead of silently failing to execute
the test suite.
2014-09-23 22:09:44 -03:00
12 changed files with 346 additions and 270 deletions

View File

@@ -15,3 +15,4 @@ cd44a941c833c098e4899fe3d42a96703754d0d5 1.5
1d27987c267577899350a25ba5828d55d87083ad 1.8 1d27987c267577899350a25ba5828d55d87083ad 1.8
5c5cb6d59e12e566fbb0217aea718dc31578bee1 1.9 5c5cb6d59e12e566fbb0217aea718dc31578bee1 1.9
4406fc2a6427fadc021ed7e43e7aa5032b1ea91f 1.10 4406fc2a6427fadc021ed7e43e7aa5032b1ea91f 1.10
220f6e46eb71a6212ccbe6b67b9e6edcf8ee4fa5 1.11

View File

@@ -1,3 +1,13 @@
1.12
-------------------------
- fix issue594: properly report errors when the test collection
is random. Thanks Bruno Oliveira.
- some internal test suite adaptation (to become forward
compatible with the upcoming pytest-2.8)
1.11 1.11
------------------------- -------------------------

View File

@@ -1,212 +1,215 @@
xdist: pytest distributed testing plugin .. image:: https://drone.io/bitbucket.org/pytest-dev/pytest-xdist/status.png
=============================================================== :target: https://drone.io/bitbucket.org/pytest-dev/pytest-xdist/latest
.. image:: https://pypip.in/v/pytest-xdist/badge.png
The `pytest-xdist`_ plugin extends py.test with some unique :target: https://pypi.python.org/pypi/pytest-xdist
test execution modes:
xdist: pytest distributed testing plugin
* test run parallelization_: if you have multiple CPUs or hosts you can use ============================
those for a combined test run. This allows to speed up
development or to use special resources of `remote machines`_. The `pytest-xdist`_ plugin extends py.test with some unique
test execution modes:
* ``--boxed``: (not available on Windows) run each test in a boxed_
subprocess to survive ``SEGFAULTS`` or otherwise dying processes * test run parallelization_: if you have multiple CPUs or hosts you can use
those for a combined test run. This allows to speed up
* ``--looponfail``: run your tests repeatedly in a subprocess. After each run development or to use special resources of `remote machines`_.
py.test waits until a file in your project changes and then re-runs
the previously failing tests. This is repeated until all tests pass * ``--boxed``: (not available on Windows) run each test in a boxed_
after which again a full run is performed. subprocess to survive ``SEGFAULTS`` or otherwise dying processes
* `Multi-Platform`_ coverage: you can specify different Python interpreters * ``--looponfail``: run your tests repeatedly in a subprocess. After each run
or different platforms and run tests in parallel on all of them. py.test waits until a file in your project changes and then re-runs
the previously failing tests. This is repeated until all tests pass
Before running tests remotely, ``py.test`` efficiently "rsyncs" your after which again a full run is performed.
program source code to the remote place. All test results
are reported back and displayed to your local terminal. * `Multi-Platform`_ coverage: you can specify different Python interpreters
You may specify different Python versions and interpreters. or different platforms and run tests in parallel on all of them.
Before running tests remotely, ``py.test`` efficiently "rsyncs" your
Installation program source code to the remote place. All test results
----------------------- are reported back and displayed to your local terminal.
You may specify different Python versions and interpreters.
Install the plugin with::
easy_install pytest-xdist Installation
-----------------------
# or
Install the plugin with::
pip install pytest-xdist
easy_install pytest-xdist
or use the package in develope/in-place mode with
a checkout of the `pytest-xdist repository`_ :: # or
python setup.py develop pip install pytest-xdist
Usage examples or use the package in develope/in-place mode with
--------------------- a checkout of the `pytest-xdist repository`_ ::
.. _parallelization: python setup.py develop
Speed up test runs by sending tests to multiple CPUs Usage examples
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ---------------------
To send tests to multiple CPUs, type:: .. _parallelization:
py.test -n NUM Speed up test runs by sending tests to multiple CPUs
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Especially for longer running tests or tests requiring
a lot of IO this can lead to considerable speed ups. To send tests to multiple CPUs, type::
py.test -n NUM
Running tests in a Python subprocess
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Especially for longer running tests or tests requiring
a lot of IO this can lead to considerable speed ups.
To instantiate a python2.5 sub process and send tests to it, you may type::
py.test -d --tx popen//python=python2.5 Running tests in a Python subprocess
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
This will start a subprocess which is run with the "python2.5"
Python interpreter, found in your system binary lookup path. To instantiate a python2.5 sub process and send tests to it, you may type::
If you prefix the --tx option value like this:: py.test -d --tx popen//python=python2.5
--tx 3*popen//python=python2.5 This will start a subprocess which is run with the "python2.5"
Python interpreter, found in your system binary lookup path.
then three subprocesses would be created and tests
will be load-balanced across these three processes. If you prefix the --tx option value like this::
.. _boxed: --tx 3*popen//python=python2.5
Running tests in a boxed subprocess then three subprocesses would be created and tests
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ will be load-balanced across these three processes.
If you have tests involving C or C++ libraries you might have to deal .. _boxed:
with tests crashing the process. For this case you may use the boxing
options:: Running tests in a boxed subprocess
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
py.test --boxed
If you have tests involving C or C++ libraries you might have to deal
which will run each test in a subprocess and will report if a test with tests crashing the process. For this case you may use the boxing
crashed the process. You can also combine this option with options::
running multiple processes to speed up the test run and use your CPU cores::
py.test --boxed
py.test -n3 --boxed
which will run each test in a subprocess and will report if a test
this would run 3 testing subprocesses in parallel which each crashed the process. You can also combine this option with
create new boxed subprocesses for each test. running multiple processes to speed up the test run and use your CPU cores::
py.test -n3 --boxed
.. _`remote machines`:
this would run 3 testing subprocesses in parallel which each
Sending tests to remote SSH accounts create new boxed subprocesses for each test.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Suppose you have a package ``mypkg`` which contains some .. _`remote machines`:
tests that you can successfully run locally. And you
have a ssh-reachable machine ``myhost``. Then Sending tests to remote SSH accounts
you can ad-hoc distribute your tests by typing:: +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
py.test -d --tx ssh=myhostpopen --rsyncdir mypkg mypkg Suppose you have a package ``mypkg`` which contains some
tests that you can successfully run locally. And you
This will synchronize your ``mypkg`` package directory have a ssh-reachable machine ``myhost``. Then
to an remote ssh account and then locally collect tests you can ad-hoc distribute your tests by typing::
and send them to remote places for execution.
py.test -d --tx ssh=myhostpopen --rsyncdir mypkg mypkg
You can specify multiple ``--rsyncdir`` directories
to be sent to the remote side. This will synchronize your ``mypkg`` package directory
to an remote ssh account and then locally collect tests
**NOTE:** For py.test to collect and send tests correctly and send them to remote places for execution.
you not only need to make sure all code and tests
directories are rsynced, but that any test (sub) directory You can specify multiple ``--rsyncdir`` directories
also has an ``__init__.py`` file because internally to be sent to the remote side.
py.test references tests as a fully qualified python
module path. **You will otherwise get strange errors** **NOTE:** For py.test to collect and send tests correctly
during setup of the remote side. you not only need to make sure all code and tests
directories are rsynced, but that any test (sub) directory
You can specify multiple ``--rsyncignore`` glob-patterns also has an ``__init__.py`` file because internally
to be ignored when file are sent to the remote side. py.test references tests as a fully qualified python
There are also internal ignores: .*, *.pyc, *.pyo, *~ module path. **You will otherwise get strange errors**
Those you cannot override using rsyncignore command-line or during setup of the remote side.
ini-file option(s).
You can specify multiple ``--rsyncignore`` glob-patterns
to be ignored when file are sent to the remote side.
Sending tests to remote Socket Servers There are also internal ignores: .*, *.pyc, *.pyo, *~
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Those you cannot override using rsyncignore command-line or
ini-file option(s).
Download the single-module `socketserver.py`_ Python program
and run it like this::
Sending tests to remote Socket Servers
python socketserver.py +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
It will tell you that it starts listening on the default Download the single-module `socketserver.py`_ Python program
port. You can now on your home machine specify this and run it like this::
new socket host with something like this::
python socketserver.py
py.test -d --tx socket=192.168.1.102:8888 --rsyncdir mypkg mypkg
It will tell you that it starts listening on the default
port. You can now on your home machine specify this
.. _`atonce`: new socket host with something like this::
.. _`Multi-Platform`:
py.test -d --tx socket=192.168.1.102:8888 --rsyncdir mypkg mypkg
Running tests on many platforms at once
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ .. _`atonce`:
.. _`Multi-Platform`:
The basic command to run tests on multiple platforms is::
py.test --dist=each --tx=spec1 --tx=spec2 Running tests on many platforms at once
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
If you specify a windows host, an OSX host and a Linux
environment this command will send each tests to all The basic command to run tests on multiple platforms is::
platforms - and report back failures from all platforms
at once. The specifications strings use the `xspec syntax`_. py.test --dist=each --tx=spec1 --tx=spec2
.. _`xspec syntax`: http://codespeak.net/execnet/trunk/basics.html#xspec If you specify a windows host, an OSX host and a Linux
environment this command will send each tests to all
.. _`socketserver.py`: http://bitbucket.org/hpk42/execnet/raw/2af991418160/execnet/script/socketserver.py platforms - and report back failures from all platforms
at once. The specifications strings use the `xspec syntax`_.
.. _`execnet`: http://codespeak.net/execnet
.. _`xspec syntax`: http://codespeak.net/execnet/trunk/basics.html#xspec
Specifying test exec environments in an ini file
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ .. _`socketserver.py`: http://bitbucket.org/hpk42/execnet/raw/2af991418160/execnet/script/socketserver.py
pytest (since version 2.0) supports ini-style cofiguration. .. _`execnet`: http://codespeak.net/execnet
You can for example make running with three subprocesses
your default like this:: Specifying test exec environments in an ini file
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[pytest]
addopts = -n3 pytest (since version 2.0) supports ini-style cofiguration.
You can for example make running with three subprocesses
You can also add default environments like this:: your default like this::
[pytest] [pytest]
addopts = --tx ssh=myhost//python=python2.5 --tx ssh=myhost//python=python2.6 addopts = -n3
and then just type:: You can also add default environments like this::
py.test --dist=each [pytest]
addopts = --tx ssh=myhost//python=python2.5 --tx ssh=myhost//python=python2.6
to run tests in each of the environments.
and then just type::
Specifying "rsync" dirs in an ini-file
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ py.test --dist=each
In a ``tox.ini`` or ``setup.cfg`` file in your root project directory to run tests in each of the environments.
you may specify directories to include or to exclude in synchronisation::
Specifying "rsync" dirs in an ini-file
[pytest] +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
rsyncdirs = . mypkg helperpkg
rsyncignore = .hg In a ``tox.ini`` or ``setup.cfg`` file in your root project directory
you may specify directories to include or to exclude in synchronisation::
These directory specifications are relative to the directory
where the configuration file was found. [pytest]
rsyncdirs = . mypkg helperpkg
.. _`pytest-xdist`: http://pypi.python.org/pypi/pytest-xdist rsyncignore = .hg
.. _`pytest-xdist repository`: http://bitbucket.org/hpk42/pytest-xdist
.. _`pytest`: http://pytest.org These directory specifications are relative to the directory
where the configuration file was found.
Issue and Bug Tracker
------------------------ .. _`pytest-xdist`: http://pypi.python.org/pypi/pytest-xdist
.. _`pytest-xdist repository`: http://bitbucket.org/pytest-dev/pytest-xdist
Please use the pytest issue tracker for bugs in this plugin, see https://bitbucket.org/hpk42/pytest/issues . .. _`pytest`: http://pytest.org
Issue and Bug Tracker
------------------------
Please use the pytest issue tracker for bugs in this plugin, see https://bitbucket.org/hpk42/pytest/issues .

View File

@@ -2,7 +2,7 @@ from setuptools import setup
setup( setup(
name="pytest-xdist", name="pytest-xdist",
version='1.11', version='1.12',
description='py.test xdist plugin for distributed testing and loop-on-failing modes', description='py.test xdist plugin for distributed testing and loop-on-failing modes',
long_description=open('README.txt').read(), long_description=open('README.txt').read(),
license='MIT', license='MIT',

View File

@@ -113,7 +113,7 @@ class TestDistribution:
import py import py
assert tmpdir.relto(py.path.local(%r)), tmpdir assert tmpdir.relto(py.path.local(%r)), tmpdir
""" % str(testdir.tmpdir)) """ % str(testdir.tmpdir))
result = testdir.runpytest(p1, "-n1") result = testdir.runpytest_subprocess(p1, "-n1")
assert result.ret == 0 assert result.ret == 0
result.stdout.fnmatch_lines([ result.stdout.fnmatch_lines([
"*1 passed*", "*1 passed*",
@@ -243,7 +243,7 @@ class TestDistribution:
print ("s2call-finished") print ("s2call-finished")
""") """)
args = ["-n1", "--debug"] args = ["-n1", "--debug"]
result = testdir.runpytest(*args) result = testdir.runpytest_subprocess(*args)
s = result.stdout.str() s = result.stdout.str()
assert result.ret == 2 assert result.ret == 2
assert 's2call' in s assert 's2call' in s
@@ -256,9 +256,8 @@ class TestDistribution:
import time import time
time.sleep(10) time.sleep(10)
""") """)
child = testdir.spawn_pytest("-n1") child = testdir.spawn_pytest("-n1 -v")
py.std.time.sleep(0.1) child.expect(".*test_sleep.*")
child.expect(".*test session starts.*")
child.kill(2) # keyboard interrupt child.kill(2) # keyboard interrupt
child.expect(".*KeyboardInterrupt.*") child.expect(".*KeyboardInterrupt.*")
#child.expect(".*seconds.*") #child.expect(".*seconds.*")
@@ -271,7 +270,7 @@ class TestDistEach:
def test_hello(): def test_hello():
pass pass
""") """)
result = testdir.runpytest("--debug", "--dist=each", "--tx=2*popen") result = testdir.runpytest_subprocess("--debug", "--dist=each", "--tx=2*popen")
assert not result.ret assert not result.ret
result.stdout.fnmatch_lines(["*2 pass*"]) result.stdout.fnmatch_lines(["*2 pass*"])
@@ -408,7 +407,7 @@ def test_funcarg_teardown_failure(testdir):
def test_hello(myarg): def test_hello(myarg):
pass pass
""") """)
result = testdir.runpytest("--debug", p) # , "-n1") result = testdir.runpytest_subprocess("--debug", p) # , "-n1")
result.stdout.fnmatch_lines([ result.stdout.fnmatch_lines([
"*ValueError*42*", "*ValueError*42*",
"*1 passed*1 error*", "*1 passed*1 error*",
@@ -455,7 +454,7 @@ def test_issue34_pluginloading_in_subprocess(testdir):
def test_hello(): def test_hello():
assert pytest.sample_variable == "testing" assert pytest.sample_variable == "testing"
""") """)
result = testdir.runpytest("-n1", "-p", "plugin123") result = testdir.runpytest_subprocess("-n1", "-p", "plugin123")
assert result.ret == 0 assert result.ret == 0
result.stdout.fnmatch_lines([ result.stdout.fnmatch_lines([
"*1 passed*", "*1 passed*",
@@ -485,6 +484,28 @@ def test_fixture_scope_caching_issue503(testdir):
]) ])
def test_issue_594_random_parametrize(testdir):
"""
Make sure that tests that are randomly parametrized display an appropriate
error message, instead of silently skipping the entire test run.
"""
p1 = testdir.makepyfile("""
import pytest
import random
xs = list(range(10))
random.shuffle(xs)
@pytest.mark.parametrize('x', xs)
def test_foo(x):
assert 1
""")
result = testdir.runpytest(p1, '-v', '-n4')
assert result.ret == 1
result.stdout.fnmatch_lines([
"Different tests were collected between gw* and gw*",
])
class TestNodeFailure: class TestNodeFailure:
def test_load_single(self, testdir): def test_load_single(self, testdir):

View File

@@ -1,10 +1,29 @@
import py import py
import pytest
import execnet import execnet
@pytest.fixture(scope="session", autouse=True)
def _ensure_imports():
# we import some modules because pytest-2.8's testdir fixture
# will unload all modules after each test and this cause
# (unknown) problems with execnet.Group()
execnet.Group
execnet.makegateway
pytest_plugins = "pytester" pytest_plugins = "pytester"
#rsyncdirs = ['.', '../xdist', py.path.local(execnet.__file__).dirpath()] #rsyncdirs = ['.', '../xdist', py.path.local(execnet.__file__).dirpath()]
@pytest.fixture(autouse=True)
def _divert_atexit(request, monkeypatch):
import atexit
l = []
def finish():
while l:
l.pop()()
monkeypatch.setattr(atexit, "register", l.append)
request.addfinalizer(finish)
def pytest_addoption(parser): def pytest_addoption(parser):
parser.addoption('--gx', parser.addoption('--gx',
action="append", dest="gspecs", action="append", dest="gspecs",
@@ -13,6 +32,13 @@ def pytest_addoption(parser):
def pytest_funcarg__specssh(request): def pytest_funcarg__specssh(request):
return getspecssh(request.config) return getspecssh(request.config)
@pytest.fixture
def testdir(testdir):
# pytest before 2.8 did not have a runpytest_subprocess
if not hasattr(testdir, "runpytest_subprocess"):
testdir.runpytest_subprocess = testdir.runpytest
return testdir
# configuration information for tests # configuration information for tests
def getgspecs(config): def getgspecs(config):
return [execnet.XSpec(spec) return [execnet.XSpec(spec)

View File

@@ -144,24 +144,36 @@ class TestLoadScheduling:
crashitem = sched.remove_node(node) crashitem = sched.remove_node(node)
assert crashitem == collection[0] assert crashitem == collection[0]
def test_schedule_different_tests_collected(self): def test_different_tests_collected(self, testdir):
""" """
Test that LoadScheduling is logging different tests were Test that LoadScheduling is reporting collection errors when
collected by slaves when that happens. different test ids are collected by slaves.
""" """
class CollectHook(object):
"""
Dummy hook that stores collection reports.
"""
def __init__(self):
self.reports = []
def pytest_collectreport(self, report):
self.reports.append(report)
collect_hook = CollectHook()
config = testdir.parseconfig()
config.pluginmanager.register(collect_hook, "collect_hook")
node1 = MockNode() node1 = MockNode()
node2 = MockNode() node2 = MockNode()
sched = LoadScheduling(2) sched = LoadScheduling(2, config=config)
logged_messages = []
py.log.setconsumer('loadsched', logged_messages.append)
sched.addnode(node1) sched.addnode(node1)
sched.addnode(node2) sched.addnode(node2)
sched.addnode_collection(node1, ["a.py::test_1"]) sched.addnode_collection(node1, ["a.py::test_1"])
sched.addnode_collection(node2, ["a.py::test_2"]) sched.addnode_collection(node2, ["a.py::test_2"])
sched.init_distribute() sched.init_distribute()
logged_content = ''.join(x.content() for x in logged_messages) assert len(collect_hook.reports) == 1
assert 'Different tests were collected between' in logged_content rep = collect_hook.reports[0]
assert 'Different tests collected, aborting run' in logged_content assert 'Different tests were collected between' in rep.longrepr
class TestDistReporter: class TestDistReporter:

View File

@@ -1,29 +1,27 @@
import py import py
import pytest import pytest
import execnet import execnet
from xdist import slavemanage from _pytest.pytester import HookRecorder
from xdist import slavemanage, newhooks
from xdist.slavemanage import HostRSync, NodeManager from xdist.slavemanage import HostRSync, NodeManager
pytest_plugins = "pytester", pytest_plugins = "pytester"
def pytest_funcarg__hookrecorder(request): def pytest_funcarg__hookrecorder(request, config):
_pytest = request.getfuncargvalue('_pytest') hookrecorder = HookRecorder(config.pluginmanager)
config = request.getfuncargvalue('config') if hasattr(hookrecorder, "start_recording"):
return _pytest.gethookrecorder(config.hook) hookrecorder.start_recording(newhooks)
request.addfinalizer(hookrecorder.finish_recording)
return hookrecorder
def pytest_funcarg__config(request): def pytest_funcarg__config(testdir):
testdir = request.getfuncargvalue("testdir") return testdir.parseconfig()
config = testdir.parseconfig()
return config
def pytest_funcarg__mysetup(request): def pytest_funcarg__mysetup(tmpdir):
class mysetup: class mysetup:
def __init__(self, request): source = tmpdir.mkdir("source")
temp = request.getfuncargvalue("tmpdir") dest = tmpdir.mkdir("dest")
self.source = temp.mkdir("source") return mysetup()
self.dest = temp.mkdir("dest")
request.getfuncargvalue("_pytest")
return mysetup(request)
@pytest.fixture @pytest.fixture
def slavecontroller(monkeypatch): def slavecontroller(monkeypatch):
@@ -45,8 +43,7 @@ class TestNodeManagerPopen:
for spec in NodeManager(config, l, defaultchdir="abc").specs: for spec in NodeManager(config, l, defaultchdir="abc").specs:
assert spec.chdir == "abc" assert spec.chdir == "abc"
def test_popen_makegateway_events(self, config, def test_popen_makegateway_events(self, config, hookrecorder, slavecontroller):
hookrecorder, _pytest, slavecontroller):
hm = NodeManager(config, ["popen"] * 2) hm = NodeManager(config, ["popen"] * 2)
hm.setup_nodes(None) hm.setup_nodes(None)
call = hookrecorder.popcall("pytest_xdist_setupnodes") call = hookrecorder.popcall("pytest_xdist_setupnodes")
@@ -114,14 +111,6 @@ class TestNodeManagerPopen:
call = hookrecorder.popcall("pytest_xdist_rsyncfinish") call = hookrecorder.popcall("pytest_xdist_rsyncfinish")
class TestHRSync: class TestHRSync:
def pytest_funcarg__mysetup(self, request):
class mysetup:
def __init__(self, request):
tmp = request.getfuncargvalue('tmpdir')
self.source = tmp.mkdir("source")
self.dest = tmp.mkdir("dest")
return mysetup(request)
def test_hrsync_filter(self, mysetup): def test_hrsync_filter(self, mysetup):
source, _ = mysetup.source, mysetup.dest # noqa source, _ = mysetup.source, mysetup.dest # noqa
source.ensure("dir", "file.txt") source.ensure("dir", "file.txt")
@@ -151,7 +140,7 @@ class TestHRSync:
class TestNodeManager: class TestNodeManager:
@py.test.mark.xfail @py.test.mark.xfail(run=False)
def test_rsync_roots_no_roots(self, testdir, mysetup): def test_rsync_roots_no_roots(self, testdir, mysetup):
mysetup.source.ensure("dir1", "file1").write("hello") mysetup.source.ensure("dir1", "file1").write("hello")
config = testdir.parseconfig(mysetup.source) config = testdir.parseconfig(mysetup.source)

View File

@@ -1,5 +1,5 @@
[tox] [tox]
envlist=py26,py33,py34,py27,py27-pexpect,py33-pexpect,py26,py26-old,py33-old,flakes envlist=py26,py33,py34,py27,py27-pexpect,py33-pexpect,py26-old,py33-old,flakes
[testenv] [testenv]
changedir=testing changedir=testing

View File

@@ -1,2 +1,2 @@
# #
__version__ = '1.11' __version__ = '1.12'

View File

@@ -1,4 +1,5 @@
import difflib import difflib
from _pytest.runner import CollectReport
import pytest import pytest
import py import py
@@ -88,8 +89,9 @@ class EachScheduling:
elif self._removed2pending: elif self._removed2pending:
for deadnode in self._removed2pending: for deadnode in self._removed2pending:
if deadnode.gateway.spec == node.gateway.spec: if deadnode.gateway.spec == node.gateway.spec:
if collection != self.node2collection[deadnode]: dead_collection = self.node2collection[deadnode]
msg = report_collection_diff(self.collection, if collection != dead_collection:
msg = report_collection_diff(dead_collection,
collection, collection,
deadnode.gateway.id, deadnode.gateway.id,
node.gateway.id) node.gateway.id)
@@ -175,9 +177,10 @@ class LoadScheduling:
:log: A py.log.Producer instance. :log: A py.log.Producer instance.
:config: Config object, used for handling hooks.
""" """
def __init__(self, numnodes, log=None): def __init__(self, numnodes, log=None, config=None):
self.numnodes = numnodes self.numnodes = numnodes
self.node2collection = {} self.node2collection = {}
self.node2pending = {} self.node2pending = {}
@@ -187,6 +190,7 @@ class LoadScheduling:
self.log = py.log.Producer("loadsched") self.log = py.log.Producer("loadsched")
else: else:
self.log = log.loadsched self.log = log.loadsched
self.config = config
@property @property
def nodes(self): def nodes(self):
@@ -376,8 +380,9 @@ class LoadScheduling:
def _check_nodes_have_same_collection(self): def _check_nodes_have_same_collection(self):
"""Return True if all nodes have collected the same items. """Return True if all nodes have collected the same items.
If collections differ this returns False and logs the If collections differ, this method returns False while logging
collection differences as they are found. the collection differences and posting collection errors to
pytest_collectreport hook.
""" """
node_collection_items = list(self.node2collection.items()) node_collection_items = list(self.node2collection.items())
first_node, col = node_collection_items[0] first_node, col = node_collection_items[0]
@@ -390,8 +395,12 @@ class LoadScheduling:
node.gateway.id, node.gateway.id,
) )
if msg: if msg:
self.log(msg)
same_collection = False 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 return same_collection
@@ -494,7 +503,8 @@ class DSession:
numnodes = len(self.nodemanager.specs) numnodes = len(self.nodemanager.specs)
dist = self.config.getvalue("dist") dist = self.config.getvalue("dist")
if dist == "load": if dist == "load":
self.sched = LoadScheduling(numnodes, log=self.log) self.sched = LoadScheduling(numnodes, log=self.log,
config=self.config)
elif dist == "each": elif dist == "each":
self.sched = EachScheduling(numnodes, log=self.log) self.sched = EachScheduling(numnodes, log=self.log)
else: else:

View File

@@ -45,7 +45,11 @@ def pytest_addoption(parser):
# ------------------------------------------------------------------------- # -------------------------------------------------------------------------
def pytest_addhooks(pluginmanager): def pytest_addhooks(pluginmanager):
from xdist import newhooks from xdist import newhooks
pluginmanager.addhooks(newhooks) # avoid warnings with pytest-2.8
method = getattr(pluginmanager, "add_hookspecs", None)
if method is None:
method = pluginmanager.addhooks
method(newhooks)
# ------------------------------------------------------------------------- # -------------------------------------------------------------------------
# distributed testing initialization # distributed testing initialization
@@ -58,8 +62,8 @@ def pytest_cmdline_main(config):
looponfail_main(config) looponfail_main(config)
return 2 # looponfail only can get stop with ctrl-C anyway return 2 # looponfail only can get stop with ctrl-C anyway
def pytest_configure(config, __multicall__): @pytest.mark.trylast
__multicall__.execute() def pytest_configure(config):
if config.getoption("dist") != "no": if config.getoption("dist") != "no":
from xdist.dsession import DSession from xdist.dsession import DSession
session = DSession(config) session = DSession(config)