def test_custom_NONpython_collection_from_conftest(): |
o = tmpdir.ensure('customconfigtest_nonpython', dir=1) |
o.ensure('conftest.py').write("""if 1: |
import py |
class CustomItem(py.test.collect.Item): |
def run(self): |
pass |
|
class Directory(py.test.collect.Directory): |
def filefilter(self, fspath): |
return fspath.check(basestarts='check_', ext='.txt') |
def join(self, name): |
if not name.endswith('.txt'): |
return super(Directory, self).join(name) |
p = self.fspath.join(name) |
if p.check(file=1): |
return CustomItem(p, parent=self) |
""") |
checkfile = o.ensure('somedir', 'moredir', 'check_something.txt') |
|
for x in (o, checkfile, checkfile.dirpath()): |
print "checking that %s returns custom items" % (x,) |
config = py.test.config._reparse([x]) |
col = config._getcollector(x) |
assert len(list(col._tryiter(py.test.collect.Item))) == 1 |
|
|
|
-> old = o.chdir() |
try: |
config = py.test.config._reparse([]) |
out = py.std.cStringIO.StringIO() |
session = config._getsessionclass()(config, out) |
session.main() |
l = session.getitemoutcomepairs(Passed) |
assert len(l) == 1 |
finally: |
old.chdir() |
|
|
config = py.test.config._reparse([str(checkfile)]) |
out = py.std.cStringIO.StringIO() |
session = config._getsessionclass()(config, out) |
session.main() |
l = session.getitemoutcomepairs(Passed) |
assert len(l) == 1 |