From cc237b0d8ebffa978c0090425ad7874eb359caf3 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Sun, 20 Jul 2014 16:56:21 +0200 Subject: [PATCH] fix various flakes issues and add "flakes" to tox tests --- testing/acceptance_test.py | 10 ++++------ testing/conftest.py | 5 +---- testing/test_dsession.py | 1 - testing/test_looponfail.py | 2 +- testing/test_remote.py | 13 ++++++------- testing/test_slavemanage.py | 15 +++++++-------- tox.ini | 7 ++++++- xdist/dsession.py | 3 +-- xdist/looponfail.py | 3 +-- xdist/remote.py | 1 + 10 files changed, 28 insertions(+), 32 deletions(-) diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index 28275c2..9dbc57e 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -1,6 +1,4 @@ -import pytest import py -import sys class TestDistribution: def test_n1_pass(self, testdir): @@ -194,7 +192,7 @@ class TestDistribution: assert dest.join(subdir.basename).check(dir=1) def test_data_exchange(self, testdir): - c1 = testdir.makeconftest(""" + testdir.makeconftest(""" # This hook only called on master. def pytest_configure_node(node): node.slaveinput['a'] = 42 @@ -251,7 +249,7 @@ class TestDistribution: def test_keyboard_interrupt_dist(self, testdir): # xxx could be refined to check for return code - p = testdir.makepyfile(""" + testdir.makepyfile(""" def test_sleep(): import time time.sleep(10) @@ -301,7 +299,7 @@ class TestDistEach: class TestTerminalReporting: def test_pass_skip_fail(self, testdir): - p = testdir.makepyfile(""" + testdir.makepyfile(""" import py def test_ok(): pass @@ -323,7 +321,7 @@ class TestTerminalReporting: ]) def test_fail_platinfo(self, testdir): - p = testdir.makepyfile(""" + testdir.makepyfile(""" def test_func(): assert 0 """) diff --git a/testing/conftest.py b/testing/conftest.py index fbd94d8..d805f8c 100644 --- a/testing/conftest.py +++ b/testing/conftest.py @@ -7,14 +7,11 @@ pytest_plugins = "pytester" def pytest_addoption(parser): parser.addoption('--gx', - action="append", dest="gspecs", + action="append", dest="gspecs", help=("add a global test environment, XSpec-syntax. ")) def pytest_funcarg__specssh(request): return getspecssh(request.config) -def getgspecs(config): - return [execnet.XSpec(spec) - for spec in config.getvalueorskip("gspecs")] # configuration information for tests def getgspecs(config): diff --git a/testing/test_dsession.py b/testing/test_dsession.py index 414882e..ee285c5 100644 --- a/testing/test_dsession.py +++ b/testing/test_dsession.py @@ -4,7 +4,6 @@ from xdist.dsession import ( EachScheduling, report_collection_diff, ) -from _pytest import main as outcome import py import pytest import execnet diff --git a/testing/test_looponfail.py b/testing/test_looponfail.py index 4112f04..4aadb32 100644 --- a/testing/test_looponfail.py +++ b/testing/test_looponfail.py @@ -42,7 +42,7 @@ class TestStatRecorder: def test_dirchange(self, tmpdir): tmp = tmpdir - hello = tmp.ensure("dir", "hello.py") + tmp.ensure("dir", "hello.py") sd = StatRecorder([tmp]) assert not sd.fil(tmp.join("dir")) diff --git a/testing/test_remote.py b/testing/test_remote.py index 6f3c273..4a043e7 100644 --- a/testing/test_remote.py +++ b/testing/test_remote.py @@ -3,7 +3,6 @@ from xdist.slavemanage import SlaveController, unserialize_report from xdist.remote import serialize_report import execnet queue = py.builtin._tryimport("queue", "Queue") -from py.builtin import print_ import marshal WAIT_TIMEOUT = 10.0 @@ -26,7 +25,7 @@ class SlaveSetup: use_callback = False def __init__(self, request): - self.testdir = testdir = request.getfuncargvalue("testdir") + self.testdir = request.getfuncargvalue("testdir") self.request = request self.events = queue.Queue() @@ -140,7 +139,7 @@ class TestReportSerialization: class TestSlaveInteractor: def test_basic_collect_and_runtests(self, slave): - p = slave.testdir.makepyfile(""" + slave.testdir.makepyfile(""" def test_func(): pass """) @@ -170,7 +169,7 @@ class TestSlaveInteractor: assert 'slaveoutput' in ev.kwargs def test_remote_collect_skip(self, slave): - p = slave.testdir.makepyfile(""" + slave.testdir.makepyfile(""" import py py.test.skip("hello") """) @@ -187,7 +186,7 @@ class TestSlaveInteractor: assert not ev.kwargs['ids'] def test_remote_collect_fail(self, slave): - p = slave.testdir.makepyfile("""aasd qwe""") + slave.testdir.makepyfile("""aasd qwe""") slave.setup() ev = slave.popevent("collectionstart") assert not ev.kwargs @@ -201,7 +200,7 @@ class TestSlaveInteractor: assert not ev.kwargs['ids'] def test_runtests_all(self, slave): - p = slave.testdir.makepyfile(""" + slave.testdir.makepyfile(""" def test_func(): pass def test_func2(): pass """) @@ -228,7 +227,7 @@ class TestSlaveInteractor: def test_happy_run_events_converted(self, testdir, slave): py.test.xfail("implement a simple test for event production") assert not slave.use_callback - p = slave.testdir.makepyfile(""" + slave.testdir.makepyfile(""" def test_func(): pass """) diff --git a/testing/test_slavemanage.py b/testing/test_slavemanage.py index edf2abb..a94181b 100644 --- a/testing/test_slavemanage.py +++ b/testing/test_slavemanage.py @@ -1,5 +1,4 @@ import py -import os import execnet from xdist.slavemanage import HostRSync, NodeManager @@ -108,7 +107,7 @@ class TestHRSync: return mysetup(request) def test_hrsync_filter(self, mysetup): - source, dest = mysetup.source, mysetup.dest + source, _ = mysetup.source, mysetup.dest # noqa source.ensure("dir", "file.txt") source.ensure(".svn", "entries") source.ensure(".somedotfile", "moreentries") @@ -139,7 +138,7 @@ class TestNodeManager: @py.test.mark.xfail def test_rsync_roots_no_roots(self, testdir, mysetup): mysetup.source.ensure("dir1", "file1").write("hello") - config = testdir.parseconfig(source) + config = testdir.parseconfig(mysetup.source) nodemanager = NodeManager(config, ["popen//chdir=%s" % mysetup.dest]) #assert nodemanager.config.topdir == source == config.topdir nodemanager.makegateways() @@ -194,11 +193,11 @@ class TestNodeManager: def test_rsyncignore(self, testdir, mysetup): source, dest = mysetup.source, mysetup.dest dir2 = source.ensure("dir1", "dir2", dir=1) - dir5 = source.ensure("dir5", "dir6", "bogus") - dirf = source.ensure("dir5", "file") + source.ensure("dir5", "dir6", "bogus") + source.ensure("dir5", "file") dir2.ensure("hello") - dirfoo = source.ensure("foo", "bar") - dirbar = source.ensure("bar", "foo") + source.ensure("foo", "bar") + source.ensure("bar", "foo") source.join("tox.ini").write(py.std.textwrap.dedent(""" [pytest] rsyncdirs = dir1 dir5 @@ -217,7 +216,7 @@ class TestNodeManager: assert not dest.join('bar').check() def test_optimise_popen(self, testdir, mysetup): - source, dest = mysetup.source, mysetup.dest + source = mysetup.source specs = ["popen"] * 3 source.join("conftest.py").write("rsyncdirs = ['a']") source.ensure('a', dir=1) diff --git a/tox.ini b/tox.ini index 745d6cc..2ab3247 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist=py26,py32,py33,py34,py27,py27-pexpect,py33-pexpect,py26,py26-old,py33-old +envlist=py26,py32,py33,py34,py27,py27-pexpect,py33-pexpect,py26,py26-old,py33-old,flakes [testenv] changedir=testing @@ -13,6 +13,11 @@ deps={[testenv]deps} deps={[testenv]deps} pexpect +[testenv:flakes] +changedir= +deps = pytest-flakes>=0.2 +commands = py.test --flakes -m flakes testing xdist + [testenv:py26-old] deps= pytest==2.4.2 diff --git a/xdist/dsession.py b/xdist/dsession.py index 18559c4..cb58aaa 100644 --- a/xdist/dsession.py +++ b/xdist/dsession.py @@ -1,4 +1,3 @@ -import sys import difflib import pytest @@ -295,7 +294,7 @@ class DSession: self.slave_errordown(node, "keyboard-interrupt") return crashitem = self.sched.remove_node(node) - #assert not crashitem, (crashitem, node) + assert not crashitem, (crashitem, node) if self.shuttingdown and not self.sched.hasnodes(): self.session_finished = True diff --git a/xdist/looponfail.py b/xdist/looponfail.py index f71ffef..e5675a2 100644 --- a/xdist/looponfail.py +++ b/xdist/looponfail.py @@ -87,7 +87,7 @@ class RemoteControl(object): result = self.runsession() failures, reports, collection_failed = result if collection_failed: - reports = ["Collection failed, keeping previous failure set"] + pass # "Collection failed, keeping previous failure set" else: uniq_failures = [] for failure in failures: @@ -109,7 +109,6 @@ def repr_pytest_looponfailinfo(failreports, rootdirs): def init_slave_session(channel, args, option_dict): import os, sys - import py outchannel = channel.gateway.newchannel() sys.stdout = sys.stderr = outchannel.makefile('w') channel.send(outchannel) diff --git a/xdist/remote.py b/xdist/remote.py index 9007a19..a0b2cad 100644 --- a/xdist/remote.py +++ b/xdist/remote.py @@ -128,6 +128,7 @@ def remote_initconfig(option_dict, args): if __name__ == '__channelexec__': + 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):