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,5 +1,10 @@
.. 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
:target: https://pypi.python.org/pypi/pytest-xdist
xdist: pytest distributed testing plugin xdist: pytest distributed testing plugin
=============================================================== ============================
The `pytest-xdist`_ plugin extends py.test with some unique The `pytest-xdist`_ plugin extends py.test with some unique
test execution modes: test execution modes:
@@ -201,12 +206,10 @@ These directory specifications are relative to the directory
where the configuration file was found. 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`: http://bitbucket.org/hpk42/pytest-xdist .. _`pytest-xdist repository`: http://bitbucket.org/pytest-dev/pytest-xdist
.. _`pytest`: http://pytest.org .. _`pytest`: http://pytest.org
Issue and Bug Tracker Issue and Bug Tracker
------------------------ ------------------------
Please use the pytest issue tracker for bugs in this plugin, see https://bitbucket.org/hpk42/pytest/issues . 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)