(experimental) allow cmdline arguments to deep-point to a test, also remove virtually redundant session.getinitialitems() calls
--HG-- branch : trunk
This commit is contained in:
2
testing/pytest/dist/test_dsession.py
vendored
2
testing/pytest/dist/test_dsession.py
vendored
@@ -396,7 +396,7 @@ class TestDSession:
|
||||
config = testdir.parseconfig('-d', p1, '--tx=popen')
|
||||
dsession = DSession(config)
|
||||
hookrecorder = testdir.getreportrecorder(config).hookrecorder
|
||||
dsession.main([config.getfsnode(p1)])
|
||||
dsession.main([config.getnode(p1)])
|
||||
rep = hookrecorder.popcall("pytest_runtest_logreport").report
|
||||
assert rep.passed
|
||||
rep = hookrecorder.popcall("pytest_runtest_logreport").report
|
||||
|
||||
@@ -66,7 +66,7 @@ class TestCollector:
|
||||
return MyDirectory(path, parent=parent)
|
||||
""")
|
||||
config = testdir.parseconfig(hello)
|
||||
node = config.getfsnode(hello)
|
||||
node = config.getnode(hello)
|
||||
assert isinstance(node, py.test.collect.File)
|
||||
assert node.name == "hello.xxx"
|
||||
names = config._rootcol.totrail(node)
|
||||
@@ -84,7 +84,7 @@ class TestCollectFS:
|
||||
tmpdir.ensure("normal", 'test_found.py')
|
||||
tmpdir.ensure('test_found.py')
|
||||
|
||||
col = testdir.parseconfig(tmpdir).getfsnode(tmpdir)
|
||||
col = testdir.parseconfig(tmpdir).getnode(tmpdir)
|
||||
items = col.collect()
|
||||
names = [x.name for x in items]
|
||||
assert len(items) == 2
|
||||
@@ -93,7 +93,7 @@ class TestCollectFS:
|
||||
|
||||
def test_found_certain_testfiles(self, testdir):
|
||||
p1 = testdir.makepyfile(test_found = "pass", found_test="pass")
|
||||
col = testdir.parseconfig(p1).getfsnode(p1.dirpath())
|
||||
col = testdir.parseconfig(p1).getnode(p1.dirpath())
|
||||
items = col.collect() # Directory collect returns files sorted by name
|
||||
assert len(items) == 2
|
||||
assert items[1].name == 'test_found.py'
|
||||
@@ -106,7 +106,7 @@ class TestCollectFS:
|
||||
testdir.makepyfile(test_two="hello")
|
||||
p1.dirpath().mkdir("dir2")
|
||||
config = testdir.parseconfig()
|
||||
col = config.getfsnode(p1.dirpath())
|
||||
col = config.getnode(p1.dirpath())
|
||||
names = [x.name for x in col.collect()]
|
||||
assert names == ["dir1", "dir2", "test_one.py", "test_two.py", "x"]
|
||||
|
||||
@@ -120,7 +120,7 @@ class TestCollectPluginHookRelay:
|
||||
config = testdir.Config()
|
||||
config.pluginmanager.register(Plugin())
|
||||
config.parse([tmpdir])
|
||||
col = config.getfsnode(tmpdir)
|
||||
col = config.getnode(tmpdir)
|
||||
testdir.makefile(".abc", "xyz")
|
||||
res = col.collect()
|
||||
assert len(wascalled) == 1
|
||||
@@ -203,20 +203,36 @@ class TestRootCol:
|
||||
tmpdir.ensure("a", "__init__.py")
|
||||
x = tmpdir.ensure("a", "trail.py")
|
||||
config = testdir.reparseconfig([x])
|
||||
col = config.getfsnode(x)
|
||||
col = config.getnode(x)
|
||||
trail = config._rootcol.totrail(col)
|
||||
col2 = config._rootcol.fromtrail(trail)
|
||||
assert col2 == col
|
||||
|
||||
def test_totrail_topdir_and_beyond(self, testdir, tmpdir):
|
||||
config = testdir.reparseconfig()
|
||||
col = config.getfsnode(config.topdir)
|
||||
col = config.getnode(config.topdir)
|
||||
trail = config._rootcol.totrail(col)
|
||||
col2 = config._rootcol.fromtrail(trail)
|
||||
assert col2.fspath == config.topdir
|
||||
assert len(col2.listchain()) == 1
|
||||
py.test.raises(config.Error, "config.getfsnode(config.topdir.dirpath())")
|
||||
#col3 = config.getfsnode(config.topdir.dirpath())
|
||||
py.test.raises(config.Error, "config.getnode(config.topdir.dirpath())")
|
||||
#col3 = config.getnode(config.topdir.dirpath())
|
||||
#py.test.raises(ValueError,
|
||||
# "col3._totrail()")
|
||||
|
||||
def test_argid(self, testdir, tmpdir):
|
||||
cfg = testdir.parseconfig()
|
||||
p = testdir.makepyfile("def test_func(): pass")
|
||||
item = cfg.getnode("%s::test_func" % p)
|
||||
assert item.name == "test_func"
|
||||
|
||||
def test_argid_with_method(self, testdir, tmpdir):
|
||||
cfg = testdir.parseconfig()
|
||||
p = testdir.makepyfile("""
|
||||
class TestClass:
|
||||
def test_method(self): pass
|
||||
""")
|
||||
item = cfg.getnode("%s::TestClass::()::test_method" % p)
|
||||
assert item.name == "test_method"
|
||||
item = cfg.getnode("%s::TestClass::test_method" % p)
|
||||
assert item.name == "test_method"
|
||||
|
||||
@@ -117,28 +117,28 @@ class TestConfigAPI:
|
||||
py.test.raises(ValueError, "config.setsessionclass(Session1)")
|
||||
|
||||
|
||||
class TestConfigApi_getcolitems:
|
||||
def test_getcolitems_onedir(self, testdir):
|
||||
class TestConfigApi_getinitialnodes:
|
||||
def test_onedir(self, testdir):
|
||||
config = testdir.reparseconfig([testdir.tmpdir])
|
||||
colitems = config.getcolitems()
|
||||
colitems = config.getinitialnodes()
|
||||
assert len(colitems) == 1
|
||||
col = colitems[0]
|
||||
assert isinstance(col, py.test.collect.Directory)
|
||||
for col in col.listchain():
|
||||
assert col.config is config
|
||||
|
||||
def test_getcolitems_twodirs(self, testdir, tmpdir):
|
||||
def test_twodirs(self, testdir, tmpdir):
|
||||
config = testdir.reparseconfig([tmpdir, tmpdir])
|
||||
colitems = config.getcolitems()
|
||||
colitems = config.getinitialnodes()
|
||||
assert len(colitems) == 2
|
||||
col1, col2 = colitems
|
||||
assert col1.name == col2.name
|
||||
assert col1.parent == col2.parent
|
||||
|
||||
def test_getcolitems_curdir_and_subdir(self, testdir, tmpdir):
|
||||
def test_curdir_and_subdir(self, testdir, tmpdir):
|
||||
a = tmpdir.ensure("a", dir=1)
|
||||
config = testdir.reparseconfig([tmpdir, a])
|
||||
colitems = config.getcolitems()
|
||||
colitems = config.getinitialnodes()
|
||||
assert len(colitems) == 2
|
||||
col1, col2 = colitems
|
||||
assert col1.name == tmpdir.basename
|
||||
@@ -147,10 +147,10 @@ class TestConfigApi_getcolitems:
|
||||
for subcol in col.listchain():
|
||||
assert col.config is config
|
||||
|
||||
def test__getcol_global_file(self, testdir, tmpdir):
|
||||
def test_global_file(self, testdir, tmpdir):
|
||||
x = tmpdir.ensure("x.py")
|
||||
config = testdir.reparseconfig([x])
|
||||
col = config.getfsnode(x)
|
||||
col, = config.getinitialnodes()
|
||||
assert isinstance(col, py.test.collect.Module)
|
||||
assert col.name == 'x.py'
|
||||
assert col.parent.name == tmpdir.basename
|
||||
@@ -158,21 +158,21 @@ class TestConfigApi_getcolitems:
|
||||
for col in col.listchain():
|
||||
assert col.config is config
|
||||
|
||||
def test__getcol_global_dir(self, testdir, tmpdir):
|
||||
def test_global_dir(self, testdir, tmpdir):
|
||||
x = tmpdir.ensure("a", dir=1)
|
||||
config = testdir.reparseconfig([x])
|
||||
col = config.getfsnode(x)
|
||||
col, = config.getinitialnodes()
|
||||
assert isinstance(col, py.test.collect.Directory)
|
||||
print(col.listchain())
|
||||
assert col.name == 'a'
|
||||
assert isinstance(col.parent, RootCollector)
|
||||
assert col.config is config
|
||||
|
||||
def test__getcol_pkgfile(self, testdir, tmpdir):
|
||||
def test_pkgfile(self, testdir, tmpdir):
|
||||
x = tmpdir.ensure("x.py")
|
||||
tmpdir.ensure("__init__.py")
|
||||
config = testdir.reparseconfig([x])
|
||||
col = config.getfsnode(x)
|
||||
col, = config.getinitialnodes()
|
||||
assert isinstance(col, py.test.collect.Module)
|
||||
assert col.name == 'x.py'
|
||||
assert col.parent.name == x.dirpath().basename
|
||||
@@ -214,7 +214,9 @@ class TestConfig_gettopdir:
|
||||
Z = tmp.ensure('Z', dir=1)
|
||||
assert gettopdir([c]) == a
|
||||
assert gettopdir([c, Z]) == tmp
|
||||
|
||||
assert gettopdir(["%s::xyc" % c]) == a
|
||||
assert gettopdir(["%s::xyc::abc" % c]) == a
|
||||
assert gettopdir(["%s::xyc" % c, "%s::abc" % Z]) == tmp
|
||||
|
||||
def test_options_on_small_file_do_not_blow_up(testdir):
|
||||
def runfiletest(opts):
|
||||
|
||||
@@ -50,7 +50,7 @@ class TestCollectDeprecated:
|
||||
def check2(self): pass
|
||||
"""))
|
||||
config = testdir.parseconfig(somefile)
|
||||
dirnode = config.getfsnode(somefile.dirpath())
|
||||
dirnode = config.getnode(somefile.dirpath())
|
||||
colitems = dirnode.collect()
|
||||
w = recwarn.pop(DeprecationWarning)
|
||||
assert w.filename.find("conftest.py") != -1
|
||||
@@ -174,7 +174,7 @@ class TestCollectDeprecated:
|
||||
""")
|
||||
testme = testdir.makefile('xxx', testme="hello")
|
||||
config = testdir.parseconfig(testme)
|
||||
col = config.getfsnode(testme)
|
||||
col = config.getnode(testme)
|
||||
assert col.collect() == []
|
||||
|
||||
|
||||
@@ -236,11 +236,11 @@ class TestDisabled:
|
||||
""")
|
||||
config = testdir.parseconfig()
|
||||
if name == "Directory":
|
||||
config.getfsnode(testdir.tmpdir)
|
||||
config.getnode(testdir.tmpdir)
|
||||
elif name in ("Module", "File"):
|
||||
config.getfsnode(p)
|
||||
config.getnode(p)
|
||||
else:
|
||||
fnode = config.getfsnode(p)
|
||||
fnode = config.getnode(p)
|
||||
recwarn.clear()
|
||||
fnode.collect()
|
||||
w = recwarn.pop(DeprecationWarning)
|
||||
@@ -317,7 +317,7 @@ def test_conftest_non_python_items(recwarn, testdir):
|
||||
testdir.maketxtfile(x="")
|
||||
config = testdir.parseconfig()
|
||||
recwarn.clear()
|
||||
dircol = config.getfsnode(checkfile.dirpath())
|
||||
dircol = config.getnode(checkfile.dirpath())
|
||||
w = recwarn.pop(DeprecationWarning)
|
||||
assert str(w.message).find("conftest.py") != -1
|
||||
colitems = dircol.collect()
|
||||
@@ -325,7 +325,7 @@ def test_conftest_non_python_items(recwarn, testdir):
|
||||
assert colitems[0].name == "hello.xxx"
|
||||
assert colitems[0].__class__.__name__ == "CustomItem"
|
||||
|
||||
item = config.getfsnode(checkfile)
|
||||
item = config.getnode(checkfile)
|
||||
assert item.name == "hello.xxx"
|
||||
assert item.__class__.__name__ == "CustomItem"
|
||||
|
||||
@@ -358,14 +358,14 @@ def test_extra_python_files_and_functions(testdir):
|
||||
""")
|
||||
# check that directory collects "check_" files
|
||||
config = testdir.parseconfig()
|
||||
col = config.getfsnode(checkfile.dirpath())
|
||||
col = config.getnode(checkfile.dirpath())
|
||||
colitems = col.collect()
|
||||
assert len(colitems) == 1
|
||||
assert isinstance(colitems[0], py.test.collect.Module)
|
||||
|
||||
# check that module collects "check_" functions and methods
|
||||
config = testdir.parseconfig(checkfile)
|
||||
col = config.getfsnode(checkfile)
|
||||
col = config.getnode(checkfile)
|
||||
assert isinstance(col, py.test.collect.Module)
|
||||
colitems = col.collect()
|
||||
assert len(colitems) == 2
|
||||
|
||||
@@ -75,8 +75,10 @@ class TestConfigPickling:
|
||||
config2 = Config()
|
||||
config2.__setstate__(config1.__getstate__())
|
||||
assert config2.topdir == py.path.local()
|
||||
config2_relpaths = [x.relto(config2.topdir) for x in config2.args]
|
||||
config1_relpaths = [x.relto(config1.topdir) for x in config1.args]
|
||||
config2_relpaths = [py.path.local(x).relto(config2.topdir)
|
||||
for x in config2.args]
|
||||
config1_relpaths = [py.path.local(x).relto(config1.topdir)
|
||||
for x in config1.args]
|
||||
|
||||
assert config2_relpaths == config1_relpaths
|
||||
for name, value in config1.option.__dict__.items():
|
||||
@@ -138,7 +140,7 @@ class TestConfigPickling:
|
||||
testdir.chdir()
|
||||
testdir.makepyfile(hello="def test_x(): pass")
|
||||
config = testdir.parseconfig(tmpdir)
|
||||
col = config.getfsnode(config.topdir)
|
||||
col = config.getnode(config.topdir)
|
||||
io = py.io.BytesIO()
|
||||
pickler = pickle.Pickler(io)
|
||||
pickler.dump(col)
|
||||
@@ -152,7 +154,7 @@ class TestConfigPickling:
|
||||
tmpdir = testdir.tmpdir
|
||||
dir1 = tmpdir.ensure("somedir", dir=1)
|
||||
config = testdir.parseconfig()
|
||||
col = config.getfsnode(config.topdir)
|
||||
col = config.getnode(config.topdir)
|
||||
col1 = col.join(dir1.basename)
|
||||
assert col1.parent is col
|
||||
io = py.io.BytesIO()
|
||||
|
||||
Reference in New Issue
Block a user