diff --git a/CHANGELOG b/CHANGELOG index 01838d4..6093ca2 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,6 +4,9 @@ - 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 ------------------------- diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index 0dcb418..134d63c 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -113,7 +113,7 @@ class TestDistribution: import py assert tmpdir.relto(py.path.local(%r)), tmpdir """ % str(testdir.tmpdir)) - result = testdir.runpytest(p1, "-n1") + result = testdir.runpytest_subprocess(p1, "-n1") assert result.ret == 0 result.stdout.fnmatch_lines([ "*1 passed*", @@ -243,7 +243,7 @@ class TestDistribution: print ("s2call-finished") """) args = ["-n1", "--debug"] - result = testdir.runpytest(*args) + result = testdir.runpytest_subprocess(*args) s = result.stdout.str() assert result.ret == 2 assert 's2call' in s @@ -256,9 +256,8 @@ class TestDistribution: import time time.sleep(10) """) - child = testdir.spawn_pytest("-n1") - py.std.time.sleep(0.1) - child.expect(".*test session starts.*") + child = testdir.spawn_pytest("-n1 -v") + child.expect(".*test_sleep.*") child.kill(2) # keyboard interrupt child.expect(".*KeyboardInterrupt.*") #child.expect(".*seconds.*") @@ -271,7 +270,7 @@ class TestDistEach: def test_hello(): pass """) - result = testdir.runpytest("--debug", "--dist=each", "--tx=2*popen") + result = testdir.runpytest_subprocess("--debug", "--dist=each", "--tx=2*popen") assert not result.ret result.stdout.fnmatch_lines(["*2 pass*"]) @@ -408,7 +407,7 @@ def test_funcarg_teardown_failure(testdir): def test_hello(myarg): pass """) - result = testdir.runpytest("--debug", p) # , "-n1") + result = testdir.runpytest_subprocess("--debug", p) # , "-n1") result.stdout.fnmatch_lines([ "*ValueError*42*", "*1 passed*1 error*", @@ -455,7 +454,7 @@ def test_issue34_pluginloading_in_subprocess(testdir): def test_hello(): assert pytest.sample_variable == "testing" """) - result = testdir.runpytest("-n1", "-p", "plugin123") + result = testdir.runpytest_subprocess("-n1", "-p", "plugin123") assert result.ret == 0 result.stdout.fnmatch_lines([ "*1 passed*", diff --git a/testing/conftest.py b/testing/conftest.py index d805f8c..9f31a31 100644 --- a/testing/conftest.py +++ b/testing/conftest.py @@ -1,10 +1,29 @@ import py +import pytest 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" #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): parser.addoption('--gx', action="append", dest="gspecs", @@ -13,6 +32,13 @@ def pytest_addoption(parser): def pytest_funcarg__specssh(request): 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 def getgspecs(config): return [execnet.XSpec(spec) diff --git a/testing/test_slavemanage.py b/testing/test_slavemanage.py index 6c45a2f..bd14405 100644 --- a/testing/test_slavemanage.py +++ b/testing/test_slavemanage.py @@ -1,29 +1,25 @@ import py import pytest import execnet +from _pytest.pytester import HookRecorder from xdist import slavemanage from xdist.slavemanage import HostRSync, NodeManager pytest_plugins = "pytester", -def pytest_funcarg__hookrecorder(request): - _pytest = request.getfuncargvalue('_pytest') - config = request.getfuncargvalue('config') - return _pytest.gethookrecorder(config.hook) +def pytest_funcarg__hookrecorder(request, config): + hookrecorder = HookRecorder(config.pluginmanager) + request.addfinalizer(hookrecorder.finish_recording) + return hookrecorder -def pytest_funcarg__config(request): - testdir = request.getfuncargvalue("testdir") - config = testdir.parseconfig() - return config +def pytest_funcarg__config(testdir): + return testdir.parseconfig() -def pytest_funcarg__mysetup(request): +def pytest_funcarg__mysetup(tmpdir): class mysetup: - def __init__(self, request): - temp = request.getfuncargvalue("tmpdir") - self.source = temp.mkdir("source") - self.dest = temp.mkdir("dest") - request.getfuncargvalue("_pytest") - return mysetup(request) + source = tmpdir.mkdir("source") + dest = tmpdir.mkdir("dest") + return mysetup() @pytest.fixture def slavecontroller(monkeypatch): @@ -45,8 +41,7 @@ class TestNodeManagerPopen: for spec in NodeManager(config, l, defaultchdir="abc").specs: assert spec.chdir == "abc" - def test_popen_makegateway_events(self, config, - hookrecorder, _pytest, slavecontroller): + def test_popen_makegateway_events(self, config, hookrecorder, slavecontroller): hm = NodeManager(config, ["popen"] * 2) hm.setup_nodes(None) call = hookrecorder.popcall("pytest_xdist_setupnodes") @@ -114,14 +109,6 @@ class TestNodeManagerPopen: call = hookrecorder.popcall("pytest_xdist_rsyncfinish") 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): source, _ = mysetup.source, mysetup.dest # noqa source.ensure("dir", "file.txt") @@ -151,7 +138,7 @@ class TestHRSync: class TestNodeManager: - @py.test.mark.xfail + @py.test.mark.xfail(run=False) def test_rsync_roots_no_roots(self, testdir, mysetup): mysetup.source.ensure("dir1", "file1").write("hello") config = testdir.parseconfig(mysetup.source) diff --git a/xdist/plugin.py b/xdist/plugin.py index bc32104..084353c 100644 --- a/xdist/plugin.py +++ b/xdist/plugin.py @@ -58,8 +58,8 @@ def pytest_cmdline_main(config): looponfail_main(config) return 2 # looponfail only can get stop with ctrl-C anyway -def pytest_configure(config, __multicall__): - __multicall__.execute() +@pytest.mark.trylast +def pytest_configure(config): if config.getoption("dist") != "no": from xdist.dsession import DSession session = DSession(config)