def test_custom_python_collection_from_conftest(): |
o = tmpdir.ensure('customconfigtest', dir=1) |
o.ensure('conftest.py').write("""if 1: |
import py |
class MyFunction(py.test.collect.Function): |
pass |
class Directory(py.test.collect.Directory): |
def filefilter(self, fspath): |
return fspath.check(basestarts='check_', ext='.py') |
class myfuncmixin: |
Function = MyFunction |
def funcnamefilter(self, name): |
return name.startswith('check_') |
|
class Module(myfuncmixin, py.test.collect.Module): |
def classnamefilter(self, name): |
return name.startswith('CustomTestClass') |
class Instance(myfuncmixin, py.test.collect.Instance): |
pass |
""") |
checkfile = o.ensure('somedir', 'check_something.py') |
checkfile.write("""if 1: |
def check_func(): |
assert 42 == 42 |
class CustomTestClass: |
def check_method(self): |
assert 23 == 23 |
""") |
|
for x in (o, checkfile, checkfile.dirpath()): |
config = py.test.config._reparse([x]) |
|
col = config._getcollector(x) |
assert len(list(col._tryiter(py.test.collect.Item))) == 2 |
|
|
|
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) == 2 |
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) == 2 |