2009-02-27 18:18:27 +08:00
|
|
|
import py
|
|
|
|
|
2009-05-23 05:50:35 +08:00
|
|
|
pytest_plugins = "pytester"
|
2009-11-05 04:34:07 +08:00
|
|
|
import py.plugin
|
|
|
|
plugindir = py.path.local(py.plugin.__file__).dirpath()
|
2009-12-29 17:26:51 +08:00
|
|
|
from py.impl.test.pluginmanager import default_plugins
|
2009-02-27 18:18:27 +08:00
|
|
|
|
2009-05-19 05:26:16 +08:00
|
|
|
def pytest_collect_file(path, parent):
|
|
|
|
if path.basename.startswith("pytest_") and path.ext == ".py":
|
|
|
|
mod = parent.Module(path, parent=parent)
|
|
|
|
return mod
|
|
|
|
|
2009-09-06 22:59:39 +08:00
|
|
|
# for plugin test we try to automatically make sure that
|
|
|
|
# the according plugin is loaded
|
2009-05-19 05:26:16 +08:00
|
|
|
def pytest_funcarg__testdir(request):
|
2009-06-12 01:49:25 +08:00
|
|
|
testdir = request.getfuncargvalue("testdir")
|
2009-05-19 05:26:16 +08:00
|
|
|
#for obj in (request.cls, request.module):
|
|
|
|
# if hasattr(obj, 'testplugin'):
|
|
|
|
# testdir.plugins.append(obj.testplugin)
|
|
|
|
# break
|
|
|
|
#else:
|
2009-08-10 17:27:13 +08:00
|
|
|
modname = request.module.__name__.split(".")[-1]
|
2009-09-06 22:59:39 +08:00
|
|
|
if modname.startswith("test_pytest_"):
|
|
|
|
modname = modname[5:]
|
|
|
|
if plugindir.join("%s.py" % modname).check():
|
|
|
|
if modname[7:] not in default_plugins:
|
|
|
|
testdir.plugins.append(vars(request.module))
|
|
|
|
testdir.plugins.append(modname)
|
2009-08-10 17:27:13 +08:00
|
|
|
#elif modname.startswith("test_pytest"):
|
|
|
|
# pname = modname[5:]
|
|
|
|
# assert pname not in testdir.plugins
|
|
|
|
# testdir.plugins.append(pname)
|
|
|
|
# #testdir.plugins.append(vars(request.module))
|
2009-05-19 05:26:16 +08:00
|
|
|
else:
|
|
|
|
pass # raise ValueError("need better support code")
|
|
|
|
return testdir
|
2009-02-27 18:18:27 +08:00
|
|
|
|