diff --git a/py/impl/log/warning.py b/py/impl/log/warning.py index 392a83aa6..9f46feeaf 100644 --- a/py/impl/log/warning.py +++ b/py/impl/log/warning.py @@ -1,6 +1,6 @@ import py, sys -class Warning(DeprecationWarning): +class DeprecationWarning(DeprecationWarning): def __init__(self, msg, path, lineno): self.msg = msg self.path = path @@ -66,7 +66,7 @@ def warn(msg, stacklevel=1, function=None): if not filename: filename = module path = py.path.local(filename) - warning = Warning(msg, path, lineno) + warning = DeprecationWarning(msg, path, lineno) py.std.warnings.warn_explicit(warning, category=Warning, filename=str(warning.path), lineno=warning.lineno, diff --git a/py/impl/test/config.py b/py/impl/test/config.py index 6a3937e72..0e4dea5a2 100644 --- a/py/impl/test/config.py +++ b/py/impl/test/config.py @@ -188,7 +188,7 @@ class Config(object): """ 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 plugins to add options", stacklevel=2) + 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) diff --git a/testing/pytest/dist/acceptance_test.py b/testing/pytest/dist/acceptance_test.py index c845d2e98..71db04b11 100644 --- a/testing/pytest/dist/acceptance_test.py +++ b/testing/pytest/dist/acceptance_test.py @@ -1,39 +1,6 @@ import py class TestDistribution: - def test_dist_conftest_options(self, testdir): - p1 = testdir.tmpdir.ensure("dir", 'p1.py') - p1.dirpath("__init__.py").write("") - p1.dirpath("conftest.py").write(py.code.Source(""" - import py - from py.builtin import print_ - print_("importing conftest", __file__) - Option = py.test.config.Option - option = py.test.config.addoptions("someopt", - Option('--someopt', action="store_true", - dest="someopt", default=False)) - dist_rsync_roots = ['../dir'] - print_("added options", option) - print_("config file seen from conftest", py.test.config) - """)) - p1.write(py.code.Source(""" - import py - from %s import conftest - from py.builtin import print_ - def test_1(): - print_("config from test_1", py.test.config) - print_("conftest from test_1", conftest.__file__) - print_("test_1: py.test.config.option.someopt", py.test.config.option.someopt) - print_("test_1: conftest", conftest) - print_("test_1: conftest.option.someopt", conftest.option.someopt) - assert conftest.option.someopt - """ % p1.dirpath().purebasename )) - result = testdir.runpytest('-d', '--tx=popen', p1, '--someopt') - assert result.ret == 0 - extra = result.stdout.fnmatch_lines([ - "*1 passed*", - ]) - def test_manytests_to_one_popen(self, testdir): p1 = testdir.makepyfile(""" import py diff --git a/testing/pytest/test_config.py b/testing/pytest/test_config.py index 5d6a3a693..b139aa062 100644 --- a/testing/pytest/test_config.py +++ b/testing/pytest/test_config.py @@ -2,23 +2,6 @@ import py class TestConfigCmdlineParsing: - def test_config_cmdline_options(self, 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'), - ) - """) - config = testdir.reparseconfig(['-G', '17']) - assert config.option.gdest == 17 - def test_parser_addoption_default_env(self, testdir, monkeypatch): import os config = testdir.Config() diff --git a/testing/pytest/test_deprecated_api.py b/testing/pytest/test_deprecated_api.py index 71e9c6937..556c7dea0 100644 --- a/testing/pytest/test_deprecated_api.py +++ b/testing/pytest/test_deprecated_api.py @@ -210,3 +210,60 @@ class TestDisabled: def test_classlevel2(self): pass """) reprec.assertoutcome(skipped=2) + + +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_dist_conftest_options(testdir): + p1 = testdir.tmpdir.ensure("dir", 'p1.py') + p1.dirpath("__init__.py").write("") + p1.dirpath("conftest.py").write(py.code.Source(""" + import py + from py.builtin import print_ + print_("importing conftest", __file__) + Option = py.test.config.Option + option = py.test.config.addoptions("someopt", + Option('--someopt', action="store_true", + dest="someopt", default=False)) + dist_rsync_roots = ['../dir'] + print_("added options", option) + print_("config file seen from conftest", py.test.config) + """)) + p1.write(py.code.Source(""" + import py + from %s import conftest + from py.builtin import print_ + def test_1(): + print_("config from test_1", py.test.config) + print_("conftest from test_1", conftest.__file__) + print_("test_1: py.test.config.option.someopt", py.test.config.option.someopt) + print_("test_1: conftest", conftest) + print_("test_1: conftest.option.someopt", conftest.option.someopt) + assert conftest.option.someopt + """ % p1.dirpath().purebasename )) + result = testdir.runpytest('-d', '--tx=popen', p1, '--someopt') + assert result.ret == 0 + result.stderr.fnmatch_lines([ + "*Deprecation*pytest_addoptions*", + ]) + result.stdout.fnmatch_lines([ + "*1 passed*", + ]) +