[py-svn] py-trunk commit 851eded2b0e0: refine deprecations, move some over to test_deprecated_api
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Wed Dec 30 16:28:01 CET 2009
# HG changeset patch -- Bitbucket.org
# Project py-trunk
# URL http://bitbucket.org/hpk42/py-trunk/overview/
# User holger krekel <holger at merlinux.eu>
# Date 1262178440 -3600
# Node ID 851eded2b0e078a64e3e9f850181ae7a7016e435
# Parent ed40b4eda543c3e88efd7de7555fb0ebe36cd77d
refine deprecations, move some over to test_deprecated_api
--- 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*",
+ ])
+
--- 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)
--- 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()
--- 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=Non
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,
--- 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
More information about the pytest-commit
mailing list