remove all deprecated functionality and tests
--HG-- branch : trunk
This commit is contained in:
parent
17719b99a1
commit
f3fb91e296
|
@ -38,11 +38,6 @@ class Parser:
|
||||||
self._groups.insert(i+1, group)
|
self._groups.insert(i+1, group)
|
||||||
return group
|
return group
|
||||||
|
|
||||||
addgroup = getgroup
|
|
||||||
def addgroup(self, name, description=""):
|
|
||||||
py.log._apiwarn("1.1", "use getgroup() which gets-or-creates")
|
|
||||||
return self.getgroup(name, description)
|
|
||||||
|
|
||||||
def addoption(self, *opts, **attrs):
|
def addoption(self, *opts, **attrs):
|
||||||
""" add an optparse-style option. """
|
""" add an optparse-style option. """
|
||||||
self._anonymous.addoption(*opts, **attrs)
|
self._anonymous.addoption(*opts, **attrs)
|
||||||
|
@ -329,16 +324,6 @@ class Config(object):
|
||||||
return py.path.local.make_numbered_dir(prefix=basename,
|
return py.path.local.make_numbered_dir(prefix=basename,
|
||||||
keep=0, rootdir=basetemp, lock_timeout=None)
|
keep=0, rootdir=basetemp, lock_timeout=None)
|
||||||
|
|
||||||
def _getcollectclass(self, name, path):
|
|
||||||
try:
|
|
||||||
cls = self._conftest.rget(name, path)
|
|
||||||
except KeyError:
|
|
||||||
return getattr(py.test.collect, name)
|
|
||||||
else:
|
|
||||||
py.log._apiwarn(">1.1", "%r was found in a conftest.py file, "
|
|
||||||
"use pytest_collect hooks instead." % (cls,))
|
|
||||||
return cls
|
|
||||||
|
|
||||||
def getconftest_pathlist(self, name, path=None):
|
def getconftest_pathlist(self, name, path=None):
|
||||||
""" return a matching value, which needs to be sequence
|
""" return a matching value, which needs to be sequence
|
||||||
of filenames that will be returned as a list of Path
|
of filenames that will be returned as a list of Path
|
||||||
|
@ -358,19 +343,6 @@ class Config(object):
|
||||||
l.append(relroot)
|
l.append(relroot)
|
||||||
return l
|
return l
|
||||||
|
|
||||||
def addoptions(self, groupname, *specs):
|
|
||||||
# add a named group of options to the current testing session.
|
|
||||||
# This function gets invoked during testing session initialization.
|
|
||||||
py.log._apiwarn("1.0",
|
|
||||||
"define pytest_addoptions(parser) to add options", stacklevel=2)
|
|
||||||
group = self._parser.getgroup(groupname)
|
|
||||||
for opt in specs:
|
|
||||||
group._addoption_instance(opt)
|
|
||||||
return self.option
|
|
||||||
|
|
||||||
def addoption(self, *optnames, **attrs):
|
|
||||||
return self._parser.addoption(*optnames, **attrs)
|
|
||||||
|
|
||||||
def getvalueorskip(self, name, path=None):
|
def getvalueorskip(self, name, path=None):
|
||||||
""" return getvalue(name) or call py.test.skip if no value exists. """
|
""" return getvalue(name) or call py.test.skip if no value exists. """
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -68,10 +68,9 @@ class DoctestItem(py.test.collect.Item):
|
||||||
|
|
||||||
class DoctestTextfile(DoctestItem):
|
class DoctestTextfile(DoctestItem):
|
||||||
def runtest(self):
|
def runtest(self):
|
||||||
if not self._deprecated_testexecution():
|
failed, tot = py.std.doctest.testfile(
|
||||||
failed, tot = py.std.doctest.testfile(
|
str(self.fspath), module_relative=False,
|
||||||
str(self.fspath), module_relative=False,
|
raise_on_error=True, verbose=0)
|
||||||
raise_on_error=True, verbose=0)
|
|
||||||
|
|
||||||
class DoctestModule(DoctestItem):
|
class DoctestModule(DoctestItem):
|
||||||
def runtest(self):
|
def runtest(self):
|
||||||
|
|
|
@ -126,12 +126,6 @@ class MarkInfo:
|
||||||
self.args = args
|
self.args = args
|
||||||
self.kwargs = kwargs
|
self.kwargs = kwargs
|
||||||
|
|
||||||
def __getattr__(self, name):
|
|
||||||
if name[0] != '_' and name in self.kwargs:
|
|
||||||
py.log._apiwarn("1.1", "use .kwargs attribute to access key-values")
|
|
||||||
return self.kwargs[name]
|
|
||||||
raise AttributeError(name)
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<MarkInfo %r args=%r kwargs=%r>" % (
|
return "<MarkInfo %r args=%r kwargs=%r>" % (
|
||||||
self._name, self.args, self.kwargs)
|
self._name, self.args, self.kwargs)
|
||||||
|
|
|
@ -5,7 +5,6 @@ import py
|
||||||
import inspect
|
import inspect
|
||||||
import sys
|
import sys
|
||||||
import pytest
|
import pytest
|
||||||
from pytest.plugin.session import configproperty, warnoldcollect
|
|
||||||
from py._code.code import TerminalRepr
|
from py._code.code import TerminalRepr
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -52,24 +51,17 @@ def pytest_collect_file(path, parent):
|
||||||
path=path, parent=parent)
|
path=path, parent=parent)
|
||||||
|
|
||||||
def pytest_pycollect_makemodule(path, parent):
|
def pytest_pycollect_makemodule(path, parent):
|
||||||
return parent.Module(path, parent)
|
return Module(path, parent)
|
||||||
|
|
||||||
def pytest_pycollect_makeitem(__multicall__, collector, name, obj):
|
def pytest_pycollect_makeitem(__multicall__, collector, name, obj):
|
||||||
res = __multicall__.execute()
|
res = __multicall__.execute()
|
||||||
if res is not None:
|
if res is not None:
|
||||||
return res
|
return res
|
||||||
if collector._istestclasscandidate(name, obj):
|
if collector._istestclasscandidate(name, obj):
|
||||||
res = collector._deprecated_join(name)
|
return Class(name, parent=collector)
|
||||||
if res is not None:
|
|
||||||
return res
|
|
||||||
return collector.Class(name, parent=collector)
|
|
||||||
elif collector.funcnamefilter(name) and hasattr(obj, '__call__'):
|
elif collector.funcnamefilter(name) and hasattr(obj, '__call__'):
|
||||||
res = collector._deprecated_join(name)
|
|
||||||
if res is not None:
|
|
||||||
return res
|
|
||||||
if is_generator(obj):
|
if is_generator(obj):
|
||||||
# XXX deprecation warning
|
return Generator(name, parent=collector)
|
||||||
return collector.Generator(name, parent=collector)
|
|
||||||
else:
|
else:
|
||||||
return collector._genfunctions(name, obj)
|
return collector._genfunctions(name, obj)
|
||||||
|
|
||||||
|
@ -136,10 +128,6 @@ class PyobjMixin(object):
|
||||||
return fspath, lineno, modpath
|
return fspath, lineno, modpath
|
||||||
|
|
||||||
class PyCollectorMixin(PyobjMixin, pytest.collect.Collector):
|
class PyCollectorMixin(PyobjMixin, pytest.collect.Collector):
|
||||||
Class = configproperty('Class')
|
|
||||||
Instance = configproperty('Instance')
|
|
||||||
Function = configproperty('Function')
|
|
||||||
Generator = configproperty('Generator')
|
|
||||||
|
|
||||||
def funcnamefilter(self, name):
|
def funcnamefilter(self, name):
|
||||||
return name.startswith('test')
|
return name.startswith('test')
|
||||||
|
@ -147,9 +135,6 @@ class PyCollectorMixin(PyobjMixin, pytest.collect.Collector):
|
||||||
return name.startswith('Test')
|
return name.startswith('Test')
|
||||||
|
|
||||||
def collect(self):
|
def collect(self):
|
||||||
l = self._deprecated_collect()
|
|
||||||
if l is not None:
|
|
||||||
return l
|
|
||||||
# NB. we avoid random getattrs and peek in the __dict__ instead
|
# NB. we avoid random getattrs and peek in the __dict__ instead
|
||||||
dicts = [getattr(self.obj, '__dict__', {})]
|
dicts = [getattr(self.obj, '__dict__', {})]
|
||||||
for basecls in inspect.getmro(self.obj.__class__):
|
for basecls in inspect.getmro(self.obj.__class__):
|
||||||
|
@ -171,11 +156,6 @@ class PyCollectorMixin(PyobjMixin, pytest.collect.Collector):
|
||||||
l.sort(key=lambda item: item.reportinfo()[:2])
|
l.sort(key=lambda item: item.reportinfo()[:2])
|
||||||
return l
|
return l
|
||||||
|
|
||||||
def _deprecated_join(self, name):
|
|
||||||
if self.__class__.join != pytest.collect.Collector.join:
|
|
||||||
warnoldcollect()
|
|
||||||
return self.join(name)
|
|
||||||
|
|
||||||
def makeitem(self, name, obj):
|
def makeitem(self, name, obj):
|
||||||
return self.ihook.pytest_pycollect_makeitem(
|
return self.ihook.pytest_pycollect_makeitem(
|
||||||
collector=self, name=name, obj=obj)
|
collector=self, name=name, obj=obj)
|
||||||
|
@ -198,11 +178,11 @@ class PyCollectorMixin(PyobjMixin, pytest.collect.Collector):
|
||||||
plugins = getplugins(self, withpy=True)
|
plugins = getplugins(self, withpy=True)
|
||||||
gentesthook.pcall(plugins, metafunc=metafunc)
|
gentesthook.pcall(plugins, metafunc=metafunc)
|
||||||
if not metafunc._calls:
|
if not metafunc._calls:
|
||||||
return self.Function(name, parent=self)
|
return Function(name, parent=self)
|
||||||
l = []
|
l = []
|
||||||
for callspec in metafunc._calls:
|
for callspec in metafunc._calls:
|
||||||
subname = "%s[%s]" %(name, callspec.id)
|
subname = "%s[%s]" %(name, callspec.id)
|
||||||
function = self.Function(name=subname, parent=self,
|
function = Function(name=subname, parent=self,
|
||||||
callspec=callspec, callobj=funcobj, keywords={callspec.id:True})
|
callspec=callspec, callobj=funcobj, keywords={callspec.id:True})
|
||||||
l.append(function)
|
l.append(function)
|
||||||
return l
|
return l
|
||||||
|
@ -234,10 +214,6 @@ class Module(pytest.collect.File, PyCollectorMixin):
|
||||||
return mod
|
return mod
|
||||||
|
|
||||||
def setup(self):
|
def setup(self):
|
||||||
if getattr(self.obj, 'disabled', 0):
|
|
||||||
py.log._apiwarn(">1.1.1", "%r uses 'disabled' which is deprecated, "
|
|
||||||
"use pytestmark=..., see pytest_skipping plugin" % (self.obj,))
|
|
||||||
pytest.skip("%r is disabled" %(self.obj,))
|
|
||||||
if hasattr(self.obj, 'setup_module'):
|
if hasattr(self.obj, 'setup_module'):
|
||||||
#XXX: nose compat hack, move to nose plugin
|
#XXX: nose compat hack, move to nose plugin
|
||||||
# if it takes a positional arg, its probably a pytest style one
|
# if it takes a positional arg, its probably a pytest style one
|
||||||
|
@ -260,16 +236,9 @@ class Module(pytest.collect.File, PyCollectorMixin):
|
||||||
class Class(PyCollectorMixin, pytest.collect.Collector):
|
class Class(PyCollectorMixin, pytest.collect.Collector):
|
||||||
|
|
||||||
def collect(self):
|
def collect(self):
|
||||||
l = self._deprecated_collect()
|
return [Instance(name="()", parent=self)]
|
||||||
if l is not None:
|
|
||||||
return l
|
|
||||||
return [self.Instance(name="()", parent=self)]
|
|
||||||
|
|
||||||
def setup(self):
|
def setup(self):
|
||||||
if getattr(self.obj, 'disabled', 0):
|
|
||||||
py.log._apiwarn(">1.1.1", "%r uses 'disabled' which is deprecated, "
|
|
||||||
"use pytestmark=..., see pytest_skipping plugin" % (self.obj,))
|
|
||||||
pytest.skip("%r is disabled" %(self.obj,))
|
|
||||||
setup_class = getattr(self.obj, 'setup_class', None)
|
setup_class = getattr(self.obj, 'setup_class', None)
|
||||||
if setup_class is not None:
|
if setup_class is not None:
|
||||||
setup_class = getattr(setup_class, 'im_func', setup_class)
|
setup_class = getattr(setup_class, 'im_func', setup_class)
|
||||||
|
@ -387,7 +356,7 @@ class Generator(FunctionMixin, PyCollectorMixin, pytest.collect.Collector):
|
||||||
if name in seen:
|
if name in seen:
|
||||||
raise ValueError("%r generated tests with non-unique name %r" %(self, name))
|
raise ValueError("%r generated tests with non-unique name %r" %(self, name))
|
||||||
seen[name] = True
|
seen[name] = True
|
||||||
l.append(self.Function(name, self, args=args, callobj=call))
|
l.append(Function(name, self, args=args, callobj=call))
|
||||||
return l
|
return l
|
||||||
|
|
||||||
def getcallargs(self, obj):
|
def getcallargs(self, obj):
|
||||||
|
|
|
@ -71,8 +71,7 @@ def pytest_runtest_setup(item):
|
||||||
item.config._setupstate.prepare(item)
|
item.config._setupstate.prepare(item)
|
||||||
|
|
||||||
def pytest_runtest_call(item):
|
def pytest_runtest_call(item):
|
||||||
if not item._deprecated_testexecution():
|
item.runtest()
|
||||||
item.runtest()
|
|
||||||
|
|
||||||
def pytest_runtest_teardown(item):
|
def pytest_runtest_teardown(item):
|
||||||
item.config._setupstate.teardown_exact(item)
|
item.config._setupstate.teardown_exact(item)
|
||||||
|
|
|
@ -79,7 +79,7 @@ def pytest_collect_directory(path, parent):
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
return parent.Directory(path, parent=parent)
|
return Directory(path, parent=parent)
|
||||||
|
|
||||||
def pytest_report_iteminfo(item):
|
def pytest_report_iteminfo(item):
|
||||||
return item.reportinfo()
|
return item.reportinfo()
|
||||||
|
@ -296,12 +296,6 @@ def decodearg(arg):
|
||||||
arg = str(arg)
|
arg = str(arg)
|
||||||
return arg.split("::")
|
return arg.split("::")
|
||||||
|
|
||||||
def configproperty(name):
|
|
||||||
def fget(self):
|
|
||||||
#print "retrieving %r property from %s" %(name, self.fspath)
|
|
||||||
return self.config._getcollectclass(name, self.fspath)
|
|
||||||
return property(fget)
|
|
||||||
|
|
||||||
class HookProxy:
|
class HookProxy:
|
||||||
def __init__(self, node):
|
def __init__(self, node):
|
||||||
self.node = node
|
self.node = node
|
||||||
|
@ -433,8 +427,6 @@ class Collector(Node):
|
||||||
""" Collector instances create children through collect()
|
""" Collector instances create children through collect()
|
||||||
and thus iteratively build a tree.
|
and thus iteratively build a tree.
|
||||||
"""
|
"""
|
||||||
Directory = configproperty('Directory')
|
|
||||||
Module = configproperty('Module')
|
|
||||||
class CollectError(Exception):
|
class CollectError(Exception):
|
||||||
""" an error during collection, contains a custom message. """
|
""" an error during collection, contains a custom message. """
|
||||||
|
|
||||||
|
@ -470,37 +462,6 @@ class Collector(Node):
|
||||||
traceback = ntraceback.filter()
|
traceback = ntraceback.filter()
|
||||||
return traceback
|
return traceback
|
||||||
|
|
||||||
# **********************************************************************
|
|
||||||
# DEPRECATED METHODS
|
|
||||||
# **********************************************************************
|
|
||||||
|
|
||||||
def _deprecated_collect(self):
|
|
||||||
# avoid recursion:
|
|
||||||
# collect -> _deprecated_collect -> custom run() ->
|
|
||||||
# super().run() -> collect
|
|
||||||
attrname = '_depcollectentered'
|
|
||||||
if hasattr(self, attrname):
|
|
||||||
return
|
|
||||||
setattr(self, attrname, True)
|
|
||||||
method = getattr(self.__class__, 'run', None)
|
|
||||||
if method is not None and method != Collector.run:
|
|
||||||
warnoldcollect(function=method)
|
|
||||||
names = self.run()
|
|
||||||
return [x for x in [self.join(name) for name in names] if x]
|
|
||||||
|
|
||||||
def run(self):
|
|
||||||
""" DEPRECATED: returns a list of names available from this collector.
|
|
||||||
You can return an empty list. Callers of this method
|
|
||||||
must take care to catch exceptions properly.
|
|
||||||
"""
|
|
||||||
return [colitem.name for colitem in self._memocollect()]
|
|
||||||
|
|
||||||
def join(self, name):
|
|
||||||
""" DEPRECATED: return a child collector or item for the given name.
|
|
||||||
If the return value is None there is no such child.
|
|
||||||
"""
|
|
||||||
return self.collect_by_name(name)
|
|
||||||
|
|
||||||
class FSCollector(Collector):
|
class FSCollector(Collector):
|
||||||
def __init__(self, fspath, parent=None, config=None, collection=None):
|
def __init__(self, fspath, parent=None, config=None, collection=None):
|
||||||
fspath = py.path.local(fspath)
|
fspath = py.path.local(fspath)
|
||||||
|
@ -517,9 +478,6 @@ class Directory(FSCollector):
|
||||||
return path.basename not in ('CVS', '_darcs', '{arch}')
|
return path.basename not in ('CVS', '_darcs', '{arch}')
|
||||||
|
|
||||||
def collect(self):
|
def collect(self):
|
||||||
l = self._deprecated_collect()
|
|
||||||
if l is not None:
|
|
||||||
return l
|
|
||||||
l = []
|
l = []
|
||||||
for path in self.fspath.listdir(sort=True):
|
for path in self.fspath.listdir(sort=True):
|
||||||
res = self.consider(path)
|
res = self.consider(path)
|
||||||
|
@ -553,9 +511,7 @@ class Directory(FSCollector):
|
||||||
def consider_file(self, path):
|
def consider_file(self, path):
|
||||||
return self.ihook.pytest_collect_file(path=path, parent=self)
|
return self.ihook.pytest_collect_file(path=path, parent=self)
|
||||||
|
|
||||||
def consider_dir(self, path, usefilters=None):
|
def consider_dir(self, path):
|
||||||
if usefilters is not None:
|
|
||||||
py.log._apiwarn("0.99", "usefilters argument not needed")
|
|
||||||
return self.ihook.pytest_collect_directory(path=path, parent=self)
|
return self.ihook.pytest_collect_directory(path=path, parent=self)
|
||||||
|
|
||||||
class Item(Node):
|
class Item(Node):
|
||||||
|
@ -563,36 +519,5 @@ class Item(Node):
|
||||||
there might be multiple test invocation items. Attributes:
|
there might be multiple test invocation items. Attributes:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
def _deprecated_testexecution(self):
|
|
||||||
if self.__class__.run != Item.run:
|
|
||||||
warnoldtestrun(function=self.run)
|
|
||||||
elif self.__class__.execute != Item.execute:
|
|
||||||
warnoldtestrun(function=self.execute)
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
self.run()
|
|
||||||
return True
|
|
||||||
|
|
||||||
def run(self):
|
|
||||||
""" deprecated, here because subclasses might call it. """
|
|
||||||
return self.execute(self.obj)
|
|
||||||
|
|
||||||
def execute(self, obj):
|
|
||||||
""" deprecated, here because subclasses might call it. """
|
|
||||||
return obj()
|
|
||||||
|
|
||||||
def reportinfo(self):
|
def reportinfo(self):
|
||||||
return self.fspath, None, ""
|
return self.fspath, None, ""
|
||||||
|
|
||||||
def warnoldcollect(function=None):
|
|
||||||
py.log._apiwarn("1.0",
|
|
||||||
"implement collector.collect() instead of "
|
|
||||||
"collector.run() and collector.join()",
|
|
||||||
stacklevel=2, function=function)
|
|
||||||
|
|
||||||
def warnoldtestrun(function=None):
|
|
||||||
py.log._apiwarn("1.0",
|
|
||||||
"implement item.runtest() instead of "
|
|
||||||
"item.run() and item.execute()",
|
|
||||||
stacklevel=2, function=function)
|
|
||||||
|
|
||||||
|
|
|
@ -17,20 +17,20 @@ class TestMark:
|
||||||
def f(): pass
|
def f(): pass
|
||||||
mark.world(x=3, y=4)(f)
|
mark.world(x=3, y=4)(f)
|
||||||
assert f.world
|
assert f.world
|
||||||
assert f.world.x == 3
|
assert f.world.kwargs['x'] == 3
|
||||||
assert f.world.y == 4
|
assert f.world.kwargs['y'] == 4
|
||||||
|
|
||||||
def test_apply_multiple_and_merge(self):
|
def test_apply_multiple_and_merge(self):
|
||||||
mark = Mark()
|
mark = Mark()
|
||||||
def f(): pass
|
def f(): pass
|
||||||
marker = mark.world
|
marker = mark.world
|
||||||
mark.world(x=3)(f)
|
mark.world(x=3)(f)
|
||||||
assert f.world.x == 3
|
assert f.world.kwargs['x'] == 3
|
||||||
mark.world(y=4)(f)
|
mark.world(y=4)(f)
|
||||||
assert f.world.x == 3
|
assert f.world.kwargs['x'] == 3
|
||||||
assert f.world.y == 4
|
assert f.world.kwargs['y'] == 4
|
||||||
mark.world(y=1)(f)
|
mark.world(y=1)(f)
|
||||||
assert f.world.y == 1
|
assert f.world.kwargs['y'] == 1
|
||||||
assert len(f.world.args) == 0
|
assert len(f.world.args) == 0
|
||||||
|
|
||||||
def test_pytest_mark_positional(self):
|
def test_pytest_mark_positional(self):
|
||||||
|
@ -40,13 +40,6 @@ class TestMark:
|
||||||
assert f.world.args[0] == "hello"
|
assert f.world.args[0] == "hello"
|
||||||
mark.world("world")(f)
|
mark.world("world")(f)
|
||||||
|
|
||||||
def test_oldstyle_marker_access(self, recwarn):
|
|
||||||
mark = Mark()
|
|
||||||
def f(): pass
|
|
||||||
mark.world(x=1)(f)
|
|
||||||
assert f.world.x == 1
|
|
||||||
assert recwarn.pop()
|
|
||||||
|
|
||||||
class TestFunctional:
|
class TestFunctional:
|
||||||
def test_mark_per_function(self, testdir):
|
def test_mark_per_function(self, testdir):
|
||||||
p = testdir.makepyfile("""
|
p = testdir.makepyfile("""
|
||||||
|
@ -257,9 +250,11 @@ class TestKeywordSelection:
|
||||||
""")
|
""")
|
||||||
testdir.makepyfile(conftest="""
|
testdir.makepyfile(conftest="""
|
||||||
import py
|
import py
|
||||||
class Class(py.test.collect.Class):
|
def pytest_pycollect_makeitem(__multicall__, name):
|
||||||
def _keywords(self):
|
if name == "TestClass":
|
||||||
return ['xxx', self.name]
|
item = __multicall__.execute()
|
||||||
|
item.keywords['xxx'] = True
|
||||||
|
return item
|
||||||
""")
|
""")
|
||||||
for keyword in ('xxx', 'xxx test_2', 'TestClass', 'xxx -test_1',
|
for keyword in ('xxx', 'xxx test_2', 'TestClass', 'xxx -test_1',
|
||||||
'TestClass test_2', 'xxx TestClass test_2',):
|
'TestClass test_2', 'xxx TestClass test_2',):
|
||||||
|
|
|
@ -13,7 +13,6 @@ class TestModule:
|
||||||
modcol = testdir.getmodulecol("import alksdjalskdjalkjals")
|
modcol = testdir.getmodulecol("import alksdjalskdjalkjals")
|
||||||
py.test.raises(ImportError, modcol.collect)
|
py.test.raises(ImportError, modcol.collect)
|
||||||
py.test.raises(ImportError, modcol.collect)
|
py.test.raises(ImportError, modcol.collect)
|
||||||
py.test.raises(ImportError, modcol.run)
|
|
||||||
|
|
||||||
def test_import_duplicate(self, testdir):
|
def test_import_duplicate(self, testdir):
|
||||||
a = testdir.mkdir("a")
|
a = testdir.mkdir("a")
|
||||||
|
@ -36,7 +35,6 @@ class TestModule:
|
||||||
modcol = testdir.getmodulecol("this is a syntax error")
|
modcol = testdir.getmodulecol("this is a syntax error")
|
||||||
py.test.raises(modcol.CollectError, modcol.collect)
|
py.test.raises(modcol.CollectError, modcol.collect)
|
||||||
py.test.raises(modcol.CollectError, modcol.collect)
|
py.test.raises(modcol.CollectError, modcol.collect)
|
||||||
py.test.raises(modcol.CollectError, modcol.run)
|
|
||||||
|
|
||||||
def test_module_considers_pluginmanager_at_import(self, testdir):
|
def test_module_considers_pluginmanager_at_import(self, testdir):
|
||||||
modcol = testdir.getmodulecol("pytest_plugins='xasdlkj',")
|
modcol = testdir.getmodulecol("pytest_plugins='xasdlkj',")
|
||||||
|
@ -1056,9 +1054,12 @@ class TestReportInfo:
|
||||||
def test_itemreport_reportinfo(self, testdir, linecomp):
|
def test_itemreport_reportinfo(self, testdir, linecomp):
|
||||||
testdir.makeconftest("""
|
testdir.makeconftest("""
|
||||||
import py
|
import py
|
||||||
class Function(py.test.collect.Function):
|
class MyFunction(py.test.collect.Function):
|
||||||
def reportinfo(self):
|
def reportinfo(self):
|
||||||
return "ABCDE", 42, "custom"
|
return "ABCDE", 42, "custom"
|
||||||
|
def pytest_pycollect_makeitem(collector, name, obj):
|
||||||
|
if name == "test_func":
|
||||||
|
return MyFunction(name, parent=collector)
|
||||||
""")
|
""")
|
||||||
item = testdir.getitem("def test_func(): pass")
|
item = testdir.getitem("def test_func(): pass")
|
||||||
runner = item.config.pluginmanager.getplugin("runner")
|
runner = item.config.pluginmanager.getplugin("runner")
|
||||||
|
|
|
@ -116,16 +116,18 @@ class SessionTests:
|
||||||
out = failed[0].longrepr.reprcrash.message
|
out = failed[0].longrepr.reprcrash.message
|
||||||
assert out.find("""[Exception("Ha Ha fooled you, I'm a broken repr().") raised in repr()]""") != -1 #'
|
assert out.find("""[Exception("Ha Ha fooled you, I'm a broken repr().") raised in repr()]""") != -1 #'
|
||||||
|
|
||||||
def test_skip_by_conftest_directory(self, testdir):
|
def test_skip_file_by_conftest(self, testdir):
|
||||||
testdir.makepyfile(conftest="""
|
testdir.makepyfile(conftest="""
|
||||||
import py
|
import py
|
||||||
class Directory(py.test.collect.Directory):
|
def pytest_collect_file():
|
||||||
def collect(self):
|
py.test.skip("intentional")
|
||||||
py.test.skip("intentional")
|
|
||||||
""", test_file="""
|
""", test_file="""
|
||||||
def test_one(): pass
|
def test_one(): pass
|
||||||
""")
|
""")
|
||||||
reprec = testdir.inline_run(testdir.tmpdir)
|
try:
|
||||||
|
reprec = testdir.inline_run(testdir.tmpdir)
|
||||||
|
except py.test.skip.Exception:
|
||||||
|
py.test.fail("wrong skipped caught")
|
||||||
reports = reprec.getreports("pytest_collectreport")
|
reports = reprec.getreports("pytest_collectreport")
|
||||||
assert len(reports) == 1
|
assert len(reports) == 1
|
||||||
assert reports[0].skipped
|
assert reports[0].skipped
|
||||||
|
|
|
@ -173,7 +173,7 @@ class TestCollectonly:
|
||||||
linecomp.assert_contains_lines([
|
linecomp.assert_contains_lines([
|
||||||
"<Module 'test_collectonly_basic.py'>"
|
"<Module 'test_collectonly_basic.py'>"
|
||||||
])
|
])
|
||||||
item = modcol.join("test_func")
|
item = modcol.collect()[0]
|
||||||
rep.config.hook.pytest_log_itemcollect(item=item)
|
rep.config.hook.pytest_log_itemcollect(item=item)
|
||||||
linecomp.assert_contains_lines([
|
linecomp.assert_contains_lines([
|
||||||
" <Function 'test_func'>",
|
" <Function 'test_func'>",
|
||||||
|
|
|
@ -131,7 +131,7 @@ class TestCollectPluginHookRelay:
|
||||||
class Plugin:
|
class Plugin:
|
||||||
def pytest_collect_directory(self, path, parent):
|
def pytest_collect_directory(self, path, parent):
|
||||||
wascalled.append(path.basename)
|
wascalled.append(path.basename)
|
||||||
return parent.Directory(path, parent)
|
return py.test.collect.Directory(path, parent)
|
||||||
testdir.plugins.append(Plugin())
|
testdir.plugins.append(Plugin())
|
||||||
testdir.mkdir("hello")
|
testdir.mkdir("hello")
|
||||||
testdir.mkdir("world")
|
testdir.mkdir("world")
|
||||||
|
|
|
@ -1,347 +0,0 @@
|
||||||
|
|
||||||
import py
|
|
||||||
|
|
||||||
class TestCollectDeprecated:
|
|
||||||
|
|
||||||
def test_collect_with_deprecated_run_and_join(self, testdir, recwarn):
|
|
||||||
testdir.makeconftest("""
|
|
||||||
import py
|
|
||||||
|
|
||||||
class MyInstance(py.test.collect.Instance):
|
|
||||||
def run(self):
|
|
||||||
return ['check2']
|
|
||||||
def join(self, name):
|
|
||||||
if name == 'check2':
|
|
||||||
return self.Function(name=name, parent=self)
|
|
||||||
|
|
||||||
class MyClass(py.test.collect.Class):
|
|
||||||
def run(self):
|
|
||||||
return ['check2']
|
|
||||||
def join(self, name):
|
|
||||||
return MyInstance(name='i', parent=self)
|
|
||||||
|
|
||||||
class MyModule(py.test.collect.Module):
|
|
||||||
def run(self):
|
|
||||||
return ['check', 'Cls']
|
|
||||||
def join(self, name):
|
|
||||||
if name == 'check':
|
|
||||||
return self.Function(name, parent=self)
|
|
||||||
if name == 'Cls':
|
|
||||||
return MyClass(name, parent=self)
|
|
||||||
|
|
||||||
class MyDirectory(py.test.collect.Directory):
|
|
||||||
Module = MyModule
|
|
||||||
def run(self):
|
|
||||||
return ['somefile.py']
|
|
||||||
def join(self, name):
|
|
||||||
if name == "somefile.py":
|
|
||||||
return self.Module(self.fspath.join(name), parent=self)
|
|
||||||
|
|
||||||
def pytest_collect_directory(path, parent):
|
|
||||||
if path.basename == "subconf":
|
|
||||||
return MyDirectory(path, parent)
|
|
||||||
""")
|
|
||||||
subconf = testdir.mkpydir("subconf")
|
|
||||||
somefile = subconf.join("somefile.py")
|
|
||||||
somefile.write(py.code.Source("""
|
|
||||||
def check(): pass
|
|
||||||
class Cls:
|
|
||||||
def check2(self): pass
|
|
||||||
"""))
|
|
||||||
config = testdir.parseconfig(somefile)
|
|
||||||
dirnode = testdir.getnode(config, somefile.dirpath())
|
|
||||||
colitems = dirnode.collect()
|
|
||||||
w = recwarn.pop(DeprecationWarning)
|
|
||||||
assert w.filename.find("conftest.py") != -1
|
|
||||||
#recwarn.resetregistry()
|
|
||||||
#assert 0, (w.message, w.filename, w.lineno)
|
|
||||||
assert len(colitems) == 1
|
|
||||||
modcol = colitems[0]
|
|
||||||
assert modcol.name == "somefile.py"
|
|
||||||
colitems = modcol.collect()
|
|
||||||
recwarn.pop(DeprecationWarning)
|
|
||||||
assert len(colitems) == 2
|
|
||||||
assert colitems[0].name == 'check'
|
|
||||||
assert colitems[1].name == 'Cls'
|
|
||||||
clscol = colitems[1]
|
|
||||||
|
|
||||||
colitems = clscol.collect()
|
|
||||||
recwarn.pop(DeprecationWarning)
|
|
||||||
assert len(colitems) == 1
|
|
||||||
icol = colitems[0]
|
|
||||||
colitems = icol.collect()
|
|
||||||
recwarn.pop(DeprecationWarning)
|
|
||||||
assert len(colitems) == 1
|
|
||||||
assert colitems[0].name == 'check2'
|
|
||||||
|
|
||||||
def test_collect_with_deprecated_join_but_no_run(self, testdir, recwarn):
|
|
||||||
testdir.makepyfile(conftest="""
|
|
||||||
import py
|
|
||||||
|
|
||||||
class Module(py.test.collect.Module):
|
|
||||||
def funcnamefilter(self, name):
|
|
||||||
if name.startswith("check_"):
|
|
||||||
return True
|
|
||||||
return super(Module, self).funcnamefilter(name)
|
|
||||||
def join(self, name):
|
|
||||||
if name.startswith("check_"):
|
|
||||||
return self.Function(name, parent=self)
|
|
||||||
assert name != "SomeClass", "join should not be called with this name"
|
|
||||||
""")
|
|
||||||
col = testdir.getmodulecol("""
|
|
||||||
def somefunc(): pass
|
|
||||||
def check_one(): pass
|
|
||||||
class SomeClass: pass
|
|
||||||
""")
|
|
||||||
colitems = col.collect()
|
|
||||||
recwarn.pop(DeprecationWarning)
|
|
||||||
assert len(colitems) == 1
|
|
||||||
funcitem = colitems[0]
|
|
||||||
assert funcitem.name == "check_one"
|
|
||||||
|
|
||||||
def test_function_custom_run(self, testdir, recwarn):
|
|
||||||
testdir.makepyfile(conftest="""
|
|
||||||
import py
|
|
||||||
class Function(py.test.collect.Function):
|
|
||||||
def run(self):
|
|
||||||
pass
|
|
||||||
""")
|
|
||||||
modcol = testdir.getmodulecol("def test_func(): pass")
|
|
||||||
funcitem = modcol.collect()[0]
|
|
||||||
assert funcitem.name == 'test_func'
|
|
||||||
recwarn.clear()
|
|
||||||
funcitem._deprecated_testexecution()
|
|
||||||
recwarn.pop(DeprecationWarning)
|
|
||||||
|
|
||||||
def test_function_custom_execute(self, testdir, recwarn):
|
|
||||||
testdir.makepyfile(conftest="""
|
|
||||||
import py
|
|
||||||
|
|
||||||
class MyFunction(py.test.collect.Function):
|
|
||||||
def execute(self, obj, *args):
|
|
||||||
pass
|
|
||||||
Function=MyFunction
|
|
||||||
""")
|
|
||||||
modcol = testdir.getmodulecol("def test_func2(): pass")
|
|
||||||
funcitem = modcol.collect()[0]
|
|
||||||
w = recwarn.pop(DeprecationWarning) # for defining conftest.Function
|
|
||||||
assert funcitem.name == 'test_func2'
|
|
||||||
funcitem._deprecated_testexecution()
|
|
||||||
w = recwarn.pop(DeprecationWarning)
|
|
||||||
assert w.filename.find("conftest.py") != -1
|
|
||||||
|
|
||||||
def test_function_deprecated_run_execute(self, testdir, recwarn):
|
|
||||||
testdir.makepyfile(conftest="""
|
|
||||||
import py
|
|
||||||
|
|
||||||
class Function(py.test.collect.Function):
|
|
||||||
|
|
||||||
def run(self):
|
|
||||||
pass
|
|
||||||
""")
|
|
||||||
modcol = testdir.getmodulecol("def test_some2(): pass")
|
|
||||||
funcitem = modcol.collect()[0]
|
|
||||||
w = recwarn.pop(DeprecationWarning)
|
|
||||||
assert "conftest.py" in str(w.message)
|
|
||||||
|
|
||||||
recwarn.clear()
|
|
||||||
funcitem._deprecated_testexecution()
|
|
||||||
recwarn.pop(DeprecationWarning)
|
|
||||||
|
|
||||||
def test_function_deprecated_run_recursive(self, testdir):
|
|
||||||
testdir.makepyfile(conftest="""
|
|
||||||
import py
|
|
||||||
class Module(py.test.collect.Module):
|
|
||||||
def run(self):
|
|
||||||
return super(Module, self).run()
|
|
||||||
""")
|
|
||||||
modcol = testdir.getmodulecol("def test_some(): pass")
|
|
||||||
colitems = py.test.deprecated_call(modcol.collect)
|
|
||||||
funcitem = colitems[0]
|
|
||||||
|
|
||||||
def test_conftest_subclasses_Module_with_non_pyfile(self, testdir):
|
|
||||||
testdir.makepyfile(conftest="""
|
|
||||||
import py
|
|
||||||
class Module(py.test.collect.Module):
|
|
||||||
def run(self):
|
|
||||||
return []
|
|
||||||
class Directory(py.test.collect.Directory):
|
|
||||||
def consider_file(self, path):
|
|
||||||
if path.basename == "testme.xxx":
|
|
||||||
return Module(path, parent=self)
|
|
||||||
return super(Directory, self).consider_file(path)
|
|
||||||
""")
|
|
||||||
#def pytest_collect_file(path, parent):
|
|
||||||
# if path.basename == "testme.xxx":
|
|
||||||
# return Module(path, parent=parent)
|
|
||||||
testme = testdir.makefile('xxx', testme="hello")
|
|
||||||
config = testdir.parseconfig(testme)
|
|
||||||
col = testdir.getnode(config, testme)
|
|
||||||
assert col.collect() == []
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class TestDisabled:
|
|
||||||
def test_disabled_module(self, recwarn, testdir):
|
|
||||||
modcol = testdir.getmodulecol("""
|
|
||||||
disabled = True
|
|
||||||
def setup_module(mod):
|
|
||||||
raise ValueError
|
|
||||||
def test_method():
|
|
||||||
pass
|
|
||||||
""")
|
|
||||||
l = modcol.collect()
|
|
||||||
assert len(l) == 1
|
|
||||||
recwarn.clear()
|
|
||||||
py.test.raises(py.test.skip.Exception, "modcol.setup()")
|
|
||||||
recwarn.pop(DeprecationWarning)
|
|
||||||
|
|
||||||
def test_disabled_class(self, recwarn, testdir):
|
|
||||||
modcol = testdir.getmodulecol("""
|
|
||||||
class TestClass:
|
|
||||||
disabled = True
|
|
||||||
def test_method(self):
|
|
||||||
pass
|
|
||||||
""")
|
|
||||||
l = modcol.collect()
|
|
||||||
assert len(l) == 1
|
|
||||||
modcol = l[0]
|
|
||||||
assert isinstance(modcol, py.test.collect.Class)
|
|
||||||
l = modcol.collect()
|
|
||||||
assert len(l) == 1
|
|
||||||
recwarn.clear()
|
|
||||||
py.test.raises(py.test.skip.Exception, "modcol.setup()")
|
|
||||||
recwarn.pop(DeprecationWarning)
|
|
||||||
|
|
||||||
def test_disabled_class_functional(self, testdir):
|
|
||||||
reprec = testdir.inline_runsource("""
|
|
||||||
class TestSimpleClassSetup:
|
|
||||||
disabled = True
|
|
||||||
def test_classlevel(self): pass
|
|
||||||
def test_classlevel2(self): pass
|
|
||||||
""")
|
|
||||||
reprec.assertoutcome(skipped=2)
|
|
||||||
|
|
||||||
@py.test.mark.multi(name="Module Class Function".split())
|
|
||||||
def test_function_deprecated_run_execute(self, name, testdir, recwarn):
|
|
||||||
testdir.makeconftest("""
|
|
||||||
import py
|
|
||||||
class %s(py.test.collect.%s):
|
|
||||||
pass
|
|
||||||
""" % (name, name))
|
|
||||||
p = testdir.makepyfile("""
|
|
||||||
class TestClass:
|
|
||||||
def test_method(self):
|
|
||||||
pass
|
|
||||||
def test_function():
|
|
||||||
pass
|
|
||||||
""")
|
|
||||||
config = testdir.parseconfig()
|
|
||||||
if name == "Directory":
|
|
||||||
testdir.getnode(config, testdir.tmpdir)
|
|
||||||
elif name in ("Module", "File"):
|
|
||||||
testdir.getnode(config, p)
|
|
||||||
else:
|
|
||||||
fnode = testdir.getnode(config, p)
|
|
||||||
recwarn.clear()
|
|
||||||
fnode.collect()
|
|
||||||
w = recwarn.pop(DeprecationWarning)
|
|
||||||
assert "conftest.py" in str(w.message)
|
|
||||||
|
|
||||||
def test_config_cmdline_options(recwarn, testdir):
|
|
||||||
testdir.makepyfile(conftest="""
|
|
||||||
import py
|
|
||||||
def _callback(option, opt_str, value, parser, *args, **kwargs):
|
|
||||||
option.tdest = True
|
|
||||||
Option = py.test.config.Option
|
|
||||||
option = py.test.config.addoptions("testing group",
|
|
||||||
Option('-G', '--glong', action="store", default=42,
|
|
||||||
type="int", dest="gdest", help="g value."),
|
|
||||||
# XXX note: special case, option without a destination
|
|
||||||
Option('-T', '--tlong', action="callback", callback=_callback,
|
|
||||||
help='t value'),
|
|
||||||
)
|
|
||||||
""")
|
|
||||||
recwarn.clear()
|
|
||||||
config = testdir.reparseconfig(['-G', '17'])
|
|
||||||
recwarn.pop(DeprecationWarning)
|
|
||||||
assert config.option.gdest == 17
|
|
||||||
|
|
||||||
def test_conftest_non_python_items(recwarn, testdir):
|
|
||||||
testdir.makepyfile(conftest="""
|
|
||||||
import py
|
|
||||||
class CustomItem(py.test.collect.Item):
|
|
||||||
def run(self):
|
|
||||||
pass
|
|
||||||
class Directory(py.test.collect.Directory):
|
|
||||||
def consider_file(self, fspath):
|
|
||||||
if fspath.ext == ".xxx":
|
|
||||||
return CustomItem(fspath.basename, parent=self)
|
|
||||||
""")
|
|
||||||
checkfile = testdir.makefile(ext="xxx", hello="world")
|
|
||||||
testdir.makepyfile(x="")
|
|
||||||
testdir.maketxtfile(x="")
|
|
||||||
recwarn.clear()
|
|
||||||
config = testdir.parseconfig()
|
|
||||||
dircol = testdir.getnode(config, checkfile.dirpath())
|
|
||||||
|
|
||||||
w = recwarn.pop(DeprecationWarning)
|
|
||||||
assert str(w.message).find("conftest.py") != -1
|
|
||||||
colitems = dircol.collect()
|
|
||||||
assert len(colitems) == 1
|
|
||||||
assert colitems[0].name == "hello.xxx"
|
|
||||||
assert colitems[0].__class__.__name__ == "CustomItem"
|
|
||||||
|
|
||||||
item = testdir.getnode(config, checkfile)
|
|
||||||
assert item.name == "hello.xxx"
|
|
||||||
assert item.__class__.__name__ == "CustomItem"
|
|
||||||
|
|
||||||
def test_extra_python_files_and_functions(testdir, recwarn):
|
|
||||||
testdir.makepyfile(conftest="""
|
|
||||||
import py
|
|
||||||
class MyFunction(py.test.collect.Function):
|
|
||||||
pass
|
|
||||||
class Directory(py.test.collect.Directory):
|
|
||||||
def consider_file(self, path):
|
|
||||||
if path.check(fnmatch="check_*.py"):
|
|
||||||
return self.Module(path, parent=self)
|
|
||||||
return super(Directory, self).consider_file(path)
|
|
||||||
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 = testdir.makepyfile(check_file="""
|
|
||||||
def check_func():
|
|
||||||
assert 42 == 42
|
|
||||||
class CustomTestClass:
|
|
||||||
def check_method(self):
|
|
||||||
assert 23 == 23
|
|
||||||
""")
|
|
||||||
# check that directory collects "check_" files
|
|
||||||
config = testdir.parseconfig()
|
|
||||||
col = testdir.getnode(config, 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 = testdir.getnode(config, checkfile)
|
|
||||||
assert isinstance(col, py.test.collect.Module)
|
|
||||||
colitems = col.collect()
|
|
||||||
assert len(colitems) == 2
|
|
||||||
funccol = colitems[0]
|
|
||||||
assert isinstance(funccol, py.test.collect.Function)
|
|
||||||
assert funccol.name == "check_func"
|
|
||||||
clscol = colitems[1]
|
|
||||||
assert isinstance(clscol, py.test.collect.Class)
|
|
||||||
colitems = clscol.collect()[0].collect()
|
|
||||||
assert len(colitems) == 1
|
|
||||||
assert colitems[0].name == "check_method"
|
|
||||||
|
|
|
@ -10,17 +10,10 @@ class TestParser:
|
||||||
|
|
||||||
def test_group_add_and_get(self):
|
def test_group_add_and_get(self):
|
||||||
parser = parseopt.Parser()
|
parser = parseopt.Parser()
|
||||||
group = parser.addgroup("hello", description="desc")
|
group = parser.getgroup("hello", description="desc")
|
||||||
assert group.name == "hello"
|
assert group.name == "hello"
|
||||||
assert group.description == "desc"
|
assert group.description == "desc"
|
||||||
|
|
||||||
def test_addgroup_deprecation(self, recwarn):
|
|
||||||
parser = parseopt.Parser()
|
|
||||||
group = parser.addgroup("hello", description="desc")
|
|
||||||
assert recwarn.pop()
|
|
||||||
group2 = parser.getgroup("hello")
|
|
||||||
assert group == group2
|
|
||||||
|
|
||||||
def test_getgroup_simple(self):
|
def test_getgroup_simple(self):
|
||||||
parser = parseopt.Parser()
|
parser = parseopt.Parser()
|
||||||
group = parser.getgroup("hello", description="desc")
|
group = parser.getgroup("hello", description="desc")
|
||||||
|
@ -46,7 +39,7 @@ class TestParser:
|
||||||
|
|
||||||
def test_group_shortopt_lowercase(self):
|
def test_group_shortopt_lowercase(self):
|
||||||
parser = parseopt.Parser()
|
parser = parseopt.Parser()
|
||||||
group = parser.addgroup("hello")
|
group = parser.getgroup("hello")
|
||||||
py.test.raises(ValueError, """
|
py.test.raises(ValueError, """
|
||||||
group.addoption("-x", action="store_true")
|
group.addoption("-x", action="store_true")
|
||||||
""")
|
""")
|
||||||
|
|
Loading…
Reference in New Issue