diff --git a/pytest/plugin/config.py b/pytest/plugin/config.py index 89dd49c58..d9f484b6a 100644 --- a/pytest/plugin/config.py +++ b/pytest/plugin/config.py @@ -38,11 +38,6 @@ class Parser: self._groups.insert(i+1, 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): """ add an optparse-style option. """ self._anonymous.addoption(*opts, **attrs) @@ -329,16 +324,6 @@ class Config(object): return py.path.local.make_numbered_dir(prefix=basename, 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): """ return a matching value, which needs to be sequence of filenames that will be returned as a list of Path @@ -358,19 +343,6 @@ class Config(object): l.append(relroot) 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): """ return getvalue(name) or call py.test.skip if no value exists. """ try: diff --git a/pytest/plugin/doctest.py b/pytest/plugin/doctest.py index 26f51dece..a58c5d41b 100644 --- a/pytest/plugin/doctest.py +++ b/pytest/plugin/doctest.py @@ -68,10 +68,9 @@ class DoctestItem(py.test.collect.Item): class DoctestTextfile(DoctestItem): def runtest(self): - if not self._deprecated_testexecution(): - failed, tot = py.std.doctest.testfile( - str(self.fspath), module_relative=False, - raise_on_error=True, verbose=0) + failed, tot = py.std.doctest.testfile( + str(self.fspath), module_relative=False, + raise_on_error=True, verbose=0) class DoctestModule(DoctestItem): def runtest(self): diff --git a/pytest/plugin/mark.py b/pytest/plugin/mark.py index ae7470d34..4b8ed756d 100644 --- a/pytest/plugin/mark.py +++ b/pytest/plugin/mark.py @@ -126,12 +126,6 @@ class MarkInfo: self.args = args 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): return "" % ( self._name, self.args, self.kwargs) diff --git a/pytest/plugin/python.py b/pytest/plugin/python.py index 88af38cf3..0b4123712 100644 --- a/pytest/plugin/python.py +++ b/pytest/plugin/python.py @@ -5,7 +5,6 @@ import py import inspect import sys import pytest -from pytest.plugin.session import configproperty, warnoldcollect from py._code.code import TerminalRepr import pytest @@ -52,24 +51,17 @@ def pytest_collect_file(path, parent): path=path, parent=parent) def pytest_pycollect_makemodule(path, parent): - return parent.Module(path, parent) + return Module(path, parent) def pytest_pycollect_makeitem(__multicall__, collector, name, obj): res = __multicall__.execute() if res is not None: return res if collector._istestclasscandidate(name, obj): - res = collector._deprecated_join(name) - if res is not None: - return res - return collector.Class(name, parent=collector) + return Class(name, parent=collector) elif collector.funcnamefilter(name) and hasattr(obj, '__call__'): - res = collector._deprecated_join(name) - if res is not None: - return res if is_generator(obj): - # XXX deprecation warning - return collector.Generator(name, parent=collector) + return Generator(name, parent=collector) else: return collector._genfunctions(name, obj) @@ -136,10 +128,6 @@ class PyobjMixin(object): return fspath, lineno, modpath class PyCollectorMixin(PyobjMixin, pytest.collect.Collector): - Class = configproperty('Class') - Instance = configproperty('Instance') - Function = configproperty('Function') - Generator = configproperty('Generator') def funcnamefilter(self, name): return name.startswith('test') @@ -147,9 +135,6 @@ class PyCollectorMixin(PyobjMixin, pytest.collect.Collector): return name.startswith('Test') 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 dicts = [getattr(self.obj, '__dict__', {})] 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]) 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): return self.ihook.pytest_pycollect_makeitem( collector=self, name=name, obj=obj) @@ -198,11 +178,11 @@ class PyCollectorMixin(PyobjMixin, pytest.collect.Collector): plugins = getplugins(self, withpy=True) gentesthook.pcall(plugins, metafunc=metafunc) if not metafunc._calls: - return self.Function(name, parent=self) + return Function(name, parent=self) l = [] for callspec in metafunc._calls: 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}) l.append(function) return l @@ -234,10 +214,6 @@ class Module(pytest.collect.File, PyCollectorMixin): return mod 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'): #XXX: nose compat hack, move to nose plugin # 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): def collect(self): - l = self._deprecated_collect() - if l is not None: - return l - return [self.Instance(name="()", parent=self)] + return [Instance(name="()", parent=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) if setup_class is not None: setup_class = getattr(setup_class, 'im_func', setup_class) @@ -387,7 +356,7 @@ class Generator(FunctionMixin, PyCollectorMixin, pytest.collect.Collector): if name in seen: raise ValueError("%r generated tests with non-unique name %r" %(self, name)) seen[name] = True - l.append(self.Function(name, self, args=args, callobj=call)) + l.append(Function(name, self, args=args, callobj=call)) return l def getcallargs(self, obj): diff --git a/pytest/plugin/runner.py b/pytest/plugin/runner.py index f9721c60d..ca7b145a9 100644 --- a/pytest/plugin/runner.py +++ b/pytest/plugin/runner.py @@ -71,8 +71,7 @@ def pytest_runtest_setup(item): item.config._setupstate.prepare(item) def pytest_runtest_call(item): - if not item._deprecated_testexecution(): - item.runtest() + item.runtest() def pytest_runtest_teardown(item): item.config._setupstate.teardown_exact(item) diff --git a/pytest/plugin/session.py b/pytest/plugin/session.py index 5811f1109..1ea8a539c 100644 --- a/pytest/plugin/session.py +++ b/pytest/plugin/session.py @@ -79,7 +79,7 @@ def pytest_collect_directory(path, parent): break else: return - return parent.Directory(path, parent=parent) + return Directory(path, parent=parent) def pytest_report_iteminfo(item): return item.reportinfo() @@ -296,12 +296,6 @@ def decodearg(arg): arg = str(arg) 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: def __init__(self, node): self.node = node @@ -433,8 +427,6 @@ class Collector(Node): """ Collector instances create children through collect() and thus iteratively build a tree. """ - Directory = configproperty('Directory') - Module = configproperty('Module') class CollectError(Exception): """ an error during collection, contains a custom message. """ @@ -470,37 +462,6 @@ class Collector(Node): traceback = ntraceback.filter() 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): def __init__(self, fspath, parent=None, config=None, collection=None): fspath = py.path.local(fspath) @@ -517,9 +478,6 @@ class Directory(FSCollector): return path.basename not in ('CVS', '_darcs', '{arch}') def collect(self): - l = self._deprecated_collect() - if l is not None: - return l l = [] for path in self.fspath.listdir(sort=True): res = self.consider(path) @@ -553,9 +511,7 @@ class Directory(FSCollector): def consider_file(self, path): return self.ihook.pytest_collect_file(path=path, parent=self) - def consider_dir(self, path, usefilters=None): - if usefilters is not None: - py.log._apiwarn("0.99", "usefilters argument not needed") + def consider_dir(self, path): return self.ihook.pytest_collect_directory(path=path, parent=self) class Item(Node): @@ -563,36 +519,5 @@ class Item(Node): 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): 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) - diff --git a/testing/plugin/test_mark.py b/testing/plugin/test_mark.py index a340f9b73..f3a26c8b5 100644 --- a/testing/plugin/test_mark.py +++ b/testing/plugin/test_mark.py @@ -17,20 +17,20 @@ class TestMark: def f(): pass mark.world(x=3, y=4)(f) assert f.world - assert f.world.x == 3 - assert f.world.y == 4 + assert f.world.kwargs['x'] == 3 + assert f.world.kwargs['y'] == 4 def test_apply_multiple_and_merge(self): mark = Mark() def f(): pass marker = mark.world mark.world(x=3)(f) - assert f.world.x == 3 + assert f.world.kwargs['x'] == 3 mark.world(y=4)(f) - assert f.world.x == 3 - assert f.world.y == 4 + assert f.world.kwargs['x'] == 3 + assert f.world.kwargs['y'] == 4 mark.world(y=1)(f) - assert f.world.y == 1 + assert f.world.kwargs['y'] == 1 assert len(f.world.args) == 0 def test_pytest_mark_positional(self): @@ -40,13 +40,6 @@ class TestMark: assert f.world.args[0] == "hello" 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: def test_mark_per_function(self, testdir): p = testdir.makepyfile(""" @@ -257,9 +250,11 @@ class TestKeywordSelection: """) testdir.makepyfile(conftest=""" import py - class Class(py.test.collect.Class): - def _keywords(self): - return ['xxx', self.name] + def pytest_pycollect_makeitem(__multicall__, name): + if name == "TestClass": + item = __multicall__.execute() + item.keywords['xxx'] = True + return item """) for keyword in ('xxx', 'xxx test_2', 'TestClass', 'xxx -test_1', 'TestClass test_2', 'xxx TestClass test_2',): diff --git a/testing/plugin/test_python.py b/testing/plugin/test_python.py index d42024183..7f52678e9 100644 --- a/testing/plugin/test_python.py +++ b/testing/plugin/test_python.py @@ -13,7 +13,6 @@ class TestModule: modcol = testdir.getmodulecol("import alksdjalskdjalkjals") py.test.raises(ImportError, modcol.collect) py.test.raises(ImportError, modcol.collect) - py.test.raises(ImportError, modcol.run) def test_import_duplicate(self, testdir): a = testdir.mkdir("a") @@ -36,7 +35,6 @@ class TestModule: 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.run) def test_module_considers_pluginmanager_at_import(self, testdir): modcol = testdir.getmodulecol("pytest_plugins='xasdlkj',") @@ -1056,9 +1054,12 @@ class TestReportInfo: def test_itemreport_reportinfo(self, testdir, linecomp): testdir.makeconftest(""" import py - class Function(py.test.collect.Function): + class MyFunction(py.test.collect.Function): def reportinfo(self): 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") runner = item.config.pluginmanager.getplugin("runner") diff --git a/testing/plugin/test_session.py b/testing/plugin/test_session.py index 68899252f..8684be9aa 100644 --- a/testing/plugin/test_session.py +++ b/testing/plugin/test_session.py @@ -116,16 +116,18 @@ class SessionTests: out = failed[0].longrepr.reprcrash.message 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=""" import py - class Directory(py.test.collect.Directory): - def collect(self): - py.test.skip("intentional") + def pytest_collect_file(): + py.test.skip("intentional") """, test_file=""" 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") assert len(reports) == 1 assert reports[0].skipped diff --git a/testing/plugin/test_terminal.py b/testing/plugin/test_terminal.py index 3940fb54c..5e404f435 100644 --- a/testing/plugin/test_terminal.py +++ b/testing/plugin/test_terminal.py @@ -173,7 +173,7 @@ class TestCollectonly: linecomp.assert_contains_lines([ "" ]) - item = modcol.join("test_func") + item = modcol.collect()[0] rep.config.hook.pytest_log_itemcollect(item=item) linecomp.assert_contains_lines([ " ", diff --git a/testing/test_collect.py b/testing/test_collect.py index 981c8d05f..33b903036 100644 --- a/testing/test_collect.py +++ b/testing/test_collect.py @@ -131,7 +131,7 @@ class TestCollectPluginHookRelay: class Plugin: def pytest_collect_directory(self, path, parent): wascalled.append(path.basename) - return parent.Directory(path, parent) + return py.test.collect.Directory(path, parent) testdir.plugins.append(Plugin()) testdir.mkdir("hello") testdir.mkdir("world") diff --git a/testing/test_deprecated_api.py b/testing/test_deprecated_api.py deleted file mode 100644 index fb3d738d5..000000000 --- a/testing/test_deprecated_api.py +++ /dev/null @@ -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" - diff --git a/testing/test_parseopt.py b/testing/test_parseopt.py index 4acbedcd4..3d9672e1a 100644 --- a/testing/test_parseopt.py +++ b/testing/test_parseopt.py @@ -10,17 +10,10 @@ class TestParser: def test_group_add_and_get(self): parser = parseopt.Parser() - group = parser.addgroup("hello", description="desc") + group = parser.getgroup("hello", description="desc") assert group.name == "hello" 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): parser = parseopt.Parser() group = parser.getgroup("hello", description="desc") @@ -46,7 +39,7 @@ class TestParser: def test_group_shortopt_lowercase(self): parser = parseopt.Parser() - group = parser.addgroup("hello") + group = parser.getgroup("hello") py.test.raises(ValueError, """ group.addoption("-x", action="store_true") """)