some testing hygene: move _reparse testing functionality to actual test support code, un-xfail a now passing test, reduce direct py.test.config usage aiming for deprecation.

--HG--
branch : trunk
This commit is contained in:
holger krekel 2009-12-29 18:02:54 +01:00
parent 7780e74016
commit 79af98fc29
11 changed files with 70 additions and 75 deletions

View File

@ -28,21 +28,17 @@ def pytest_addoption(parser):
def pytest_funcarg__specssh(request):
return getspecssh(request.config)
def getgspecs(config=None):
if config is None:
config = py.test.config
def getgspecs(config):
return [execnet.XSpec(spec)
for spec in config.getvalueorskip("gspecs")]
# configuration information for tests
def getgspecs(config=None):
if config is None:
config = py.test.config
def getgspecs(config):
return [execnet.XSpec(spec)
for spec in config.getvalueorskip("gspecs")]
def getspecssh(config=None):
def getspecssh(config):
xspecs = getgspecs(config)
for spec in xspecs:
if spec.ssh:
@ -51,7 +47,7 @@ def getspecssh(config=None):
return spec
py.test.skip("need '--gx ssh=...'")
def getsocketspec(config=None):
def getsocketspec(config):
xspecs = getgspecs(config)
for spec in xspecs:
if spec.socket:

View File

@ -227,19 +227,6 @@ class Config(object):
self.trace("instantiated session %r" % session)
return session
def _reparse(self, args):
""" this is used from tests that want to re-invoke parse(). """
#assert args # XXX should not be empty
global config_per_process
oldconfig = py.test.config
try:
config_per_process = py.test.config = Config()
config_per_process.basetemp = self.mktemp("reparse", numbered=True)
config_per_process.parse(args)
return config_per_process
finally:
config_per_process = py.test.config = oldconfig
def getxspecs(self):
xspeclist = []
for xspec in self.getvalue("tx"):

View File

@ -205,6 +205,20 @@ class TmpTestdir:
config.parse(args)
return config
def reparseconfig(self, args=None):
""" this is used from tests that want to re-invoke parse(). """
if not args:
args = [self.tmpdir]
from py.impl.test import config
oldconfig = py.test.config
try:
c = config.config_per_process = py.test.config = pytestConfig()
c.basetemp = oldconfig.mktemp("reparse", numbered=True)
c.parse(args)
return c
finally:
config.config_per_process = py.test.config = oldconfig
def parseconfigure(self, *args):
config = self.parseconfig(*args)
config.pluginmanager.do_configure(config)

View File

@ -1,9 +1,9 @@
import py
from py.plugin.pytest_default import pytest_report_iteminfo
def test_implied_different_sessions(tmpdir):
def test_implied_different_sessions(testdir, tmpdir):
def x(*args):
config = py.test.config._reparse([tmpdir] + list(args))
config = testdir.reparseconfig([tmpdir] + list(args))
try:
config.pluginmanager.do_configure(config)
except ValueError:

View File

@ -12,9 +12,9 @@ class pytest_funcarg__mysetup:
class TestNodeManager:
@py.test.mark.xfail
def test_rsync_roots_no_roots(self, mysetup):
def test_rsync_roots_no_roots(self, testdir, mysetup):
mysetup.source.ensure("dir1", "file1").write("hello")
config = py.test.config._reparse([source])
config = testdir.reparseconfig([source])
nodemanager = NodeManager(config, ["popen//chdir=%s" % mysetup.dest])
assert nodemanager.config.topdir == source == config.topdir
nodemanager.rsync_roots()
@ -53,7 +53,7 @@ class TestNodeManager:
assert dest.join("dir1", "dir2", 'hello').check()
nodemanager.gwmanager.exit()
def test_init_rsync_roots(self, mysetup):
def test_init_rsync_roots(self, testdir, mysetup):
source, dest = mysetup.source, mysetup.dest
dir2 = source.ensure("dir1", "dir2", dir=1)
source.ensure("dir1", "somefile", dir=1)
@ -62,14 +62,14 @@ class TestNodeManager:
source.join("conftest.py").write(py.code.Source("""
rsyncdirs = ['dir1/dir2']
"""))
session = py.test.config._reparse([source]).initsession()
session = testdir.reparseconfig([source]).initsession()
nodemanager = NodeManager(session.config, ["popen//chdir=%s" % dest])
nodemanager.rsync_roots()
assert dest.join("dir2").check()
assert not dest.join("dir1").check()
assert not dest.join("bogus").check()
def test_rsyncignore(self, mysetup):
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")
@ -79,7 +79,7 @@ class TestNodeManager:
rsyncdirs = ['dir1', 'dir5']
rsyncignore = ['dir1/dir2', 'dir5/dir6']
"""))
session = py.test.config._reparse([source]).initsession()
session = testdir.reparseconfig([source]).initsession()
nodemanager = NodeManager(session.config,
["popen//chdir=%s" % dest])
nodemanager.rsync_roots()
@ -88,12 +88,12 @@ class TestNodeManager:
assert dest.join("dir5","file").check()
assert not dest.join("dir6").check()
def test_optimise_popen(self, mysetup):
def test_optimise_popen(self, testdir, mysetup):
source, dest = mysetup.source, mysetup.dest
specs = ["popen"] * 3
source.join("conftest.py").write("rsyncdirs = ['a']")
source.ensure('a', dir=1)
config = py.test.config._reparse([source])
config = testdir.reparseconfig([source])
nodemanager = NodeManager(config, specs)
nodemanager.rsync_roots()
for gwspec in nodemanager.gwmanager.specs:
@ -105,7 +105,7 @@ class TestNodeManager:
specs = ["popen"] * 2
source.join("conftest.py").write("rsyncdirs = ['a']")
source.ensure('a', dir=1)
config = py.test.config._reparse([source, '--debug'])
config = testdir.reparseconfig([source, '--debug'])
assert config.option.debug
nodemanager = NodeManager(config, specs)
reprec = testdir.getreportrecorder(config).hookrecorder

View File

@ -44,7 +44,8 @@ class MySetup:
def makenode(self, config=None):
if config is None:
config = py.test.config._reparse([])
testdir = self.request.getfuncargvalue("testdir")
config = testdir.reparseconfig([])
self.config = config
self.queue = Queue()
self.xspec = execnet.XSpec("popen")

View File

@ -52,11 +52,11 @@ class TestCollector:
parent = fn.getparent(py.test.collect.Class)
assert parent is cls
def test_totrail_and_back(self, tmpdir):
def test_totrail_and_back(self, testdir, tmpdir):
a = tmpdir.ensure("a", dir=1)
tmpdir.ensure("a", "__init__.py")
x = tmpdir.ensure("a", "trail.py")
config = py.test.config._reparse([x])
config = testdir.reparseconfig([x])
col = config.getfsnode(x)
trail = col._totrail()
assert len(trail) == 2
@ -65,8 +65,8 @@ class TestCollector:
col2 = py.test.collect.Collector._fromtrail(trail, config)
assert col2.listnames() == col.listnames()
def test_totrail_topdir_and_beyond(self, tmpdir):
config = py.test.config._reparse([tmpdir])
def test_totrail_topdir_and_beyond(self, testdir, tmpdir):
config = testdir.reparseconfig()
col = config.getfsnode(config.topdir)
trail = col._totrail()
assert len(trail) == 2

View File

@ -17,7 +17,7 @@ class TestConfigCmdlineParsing:
)
""")
testdir.chdir()
config = py.test.config._reparse(['-G', '17'])
config = testdir.reparseconfig(['-G', '17'])
assert config.option.gdest == 17
def test_parser_addoption_default_env(self, testdir, monkeypatch):
@ -56,11 +56,11 @@ class TestConfigCmdlineParsing:
)
""")
py.test.raises(ValueError, """
py.test.config._reparse(['-g', '17'])
testdir.reparseconfig(['-g', '17'])
""")
def test_parsing_again_fails(self, tmpdir):
config = py.test.config._reparse([tmpdir])
def test_parsing_again_fails(self, testdir):
config = testdir.reparseconfig([testdir.tmpdir])
py.test.raises(AssertionError, "config.parse([])")
@ -82,13 +82,11 @@ class TestConfigTmpdir:
assert tmp2 != tmp
def test_reparse(self, testdir):
config = testdir.Config()
config.basetemp = testdir.mkdir("my")
config2 = config._reparse([])
assert config2.getbasetemp().relto(config.basetemp)
config3 = config._reparse([])
assert config3.getbasetemp().relto(config.basetemp)
assert config2.basetemp != config3.basetemp
config2 = testdir.reparseconfig([])
config3 = testdir.reparseconfig([])
assert config2.getbasetemp() != config3.getbasetemp()
assert not config2.getbasetemp().relto(config3.getbasetemp())
assert not config3.getbasetemp().relto(config2.getbasetemp())
class TestConfigAPI:
@ -100,7 +98,7 @@ class TestConfigAPI:
assert config.getvalue("x") == 1
assert config.getvalue("x", o.join('sub')) == 2
py.test.raises(KeyError, "config.getvalue('y')")
config = py.test.config._reparse([str(o.join('sub'))])
config = testdir.reparseconfig([str(o.join('sub'))])
assert config.getvalue("x") == 2
assert config.getvalue("y") == 3
assert config.getvalue("x", o) == 1
@ -118,18 +116,18 @@ class TestConfigAPI:
def test_config_overwrite(self, testdir):
o = testdir.tmpdir
o.ensure("conftest.py").write("x=1")
config = py.test.config._reparse([str(o)])
config = testdir.reparseconfig([str(o)])
assert config.getvalue('x') == 1
config.option.x = 2
assert config.getvalue('x') == 2
config = py.test.config._reparse([str(o)])
config = testdir.reparseconfig([str(o)])
assert config.getvalue('x') == 1
def test_getconftest_pathlist(self, tmpdir):
def test_getconftest_pathlist(self, testdir, tmpdir):
somepath = tmpdir.join("x", "y", "z")
p = tmpdir.join("conftest.py")
p.write("pathlist = ['.', %r]" % str(somepath))
config = py.test.config._reparse([p])
config = testdir.reparseconfig([p])
assert config.getconftest_pathlist('notexist') is None
pl = config.getconftest_pathlist('pathlist')
print(pl)
@ -150,8 +148,8 @@ class TestConfigAPI:
class TestConfigApi_getcolitems:
def test_getcolitems_onedir(self, tmpdir):
config = py.test.config._reparse([tmpdir])
def test_getcolitems_onedir(self, testdir):
config = testdir.reparseconfig([testdir.tmpdir])
colitems = config.getcolitems()
assert len(colitems) == 1
col = colitems[0]
@ -159,17 +157,17 @@ class TestConfigApi_getcolitems:
for col in col.listchain():
assert col.config is config
def test_getcolitems_twodirs(self, tmpdir):
config = py.test.config._reparse([tmpdir, tmpdir])
def test_getcolitems_twodirs(self, testdir, tmpdir):
config = testdir.reparseconfig([tmpdir, tmpdir])
colitems = config.getcolitems()
assert len(colitems) == 2
col1, col2 = colitems
assert col1.name == col2.name
assert col1.parent == col2.parent
def test_getcolitems_curdir_and_subdir(self, tmpdir):
def test_getcolitems_curdir_and_subdir(self, testdir, tmpdir):
a = tmpdir.ensure("a", dir=1)
config = py.test.config._reparse([tmpdir, a])
config = testdir.reparseconfig([tmpdir, a])
colitems = config.getcolitems()
assert len(colitems) == 2
col1, col2 = colitems
@ -179,9 +177,9 @@ class TestConfigApi_getcolitems:
for subcol in col.listchain():
assert col.config is config
def test__getcol_global_file(self, tmpdir):
def test__getcol_global_file(self, testdir, tmpdir):
x = tmpdir.ensure("x.py")
config = py.test.config._reparse([x])
config = testdir.reparseconfig([x])
col = config.getfsnode(x)
assert isinstance(col, py.test.collect.Module)
assert col.name == 'x.py'
@ -190,9 +188,9 @@ class TestConfigApi_getcolitems:
for col in col.listchain():
assert col.config is config
def test__getcol_global_dir(self, tmpdir):
def test__getcol_global_dir(self, testdir, tmpdir):
x = tmpdir.ensure("a", dir=1)
config = py.test.config._reparse([x])
config = testdir.reparseconfig([x])
col = config.getfsnode(x)
assert isinstance(col, py.test.collect.Directory)
print(col.listchain())
@ -200,10 +198,10 @@ class TestConfigApi_getcolitems:
assert col.parent is None
assert col.config is config
def test__getcol_pkgfile(self, tmpdir):
def test__getcol_pkgfile(self, testdir, tmpdir):
x = tmpdir.ensure("x.py")
tmpdir.ensure("__init__.py")
config = py.test.config._reparse([x])
config = testdir.reparseconfig([x])
col = config.getfsnode(x)
assert isinstance(col, py.test.collect.Module)
assert col.name == 'x.py'
@ -215,16 +213,16 @@ class TestConfigApi_getcolitems:
class TestOptionEffects:
def test_boxed_option_default(self, testdir):
tmpdir = testdir.tmpdir.ensure("subdir", dir=1)
config = py.test.config._reparse([tmpdir])
config = testdir.reparseconfig()
config.initsession()
assert not config.option.boxed
py.test.importorskip("execnet")
config = py.test.config._reparse(['-d', tmpdir])
config = testdir.reparseconfig(['-d', tmpdir])
config.initsession()
assert not config.option.boxed
def test_is_not_boxed_by_default(self, testdir):
config = py.test.config._reparse([testdir.tmpdir])
config = testdir.reparseconfig([testdir.tmpdir])
assert not config.option.boxed
class TestConfig_gettopdir:

View File

@ -273,7 +273,6 @@ class TestPytestPluginInteractions:
assert not pluginmanager.listattr("hello")
assert pluginmanager.listattr("x") == [42]
@py.test.mark.xfail
def test_namespace_has_default_and_env_plugins(testdir):
p = testdir.makepyfile("""
import py

View File

@ -250,8 +250,8 @@ class TestFunction:
assert isinstance(modcol, py.test.collect.Module)
assert hasattr(modcol.obj, 'test_func')
def test_function_equality(self, tmpdir):
config = py.test.config._reparse([tmpdir])
def test_function_equality(self, testdir, tmpdir):
config = testdir.reparseconfig()
f1 = py.test.collect.Function(name="name",
args=(1,), callobj=isinstance)
f2 = py.test.collect.Function(name="name",
@ -271,8 +271,8 @@ class TestFunction:
assert f1 == f1_b
assert not f1 != f1_b
def test_function_equality_with_callspec(self, tmpdir):
config = py.test.config._reparse([tmpdir])
def test_function_equality_with_callspec(self, testdir, tmpdir):
config = testdir.reparseconfig()
class callspec1:
param = 1
funcargs = {}

View File

@ -1,8 +1,8 @@
import py
class SessionTests:
def test_initsession(self, tmpdir):
config = py.test.config._reparse([tmpdir])
def test_initsession(self, testdir, tmpdir):
config = testdir.reparseconfig()
session = config.initsession()
assert session.config is config