refine deprecations, move some over to test_deprecated_api
--HG-- branch : trunk
This commit is contained in:
parent
30bbf3b042
commit
d3b20e8d24
|
@ -1,6 +1,6 @@
|
||||||
import py, sys
|
import py, sys
|
||||||
|
|
||||||
class Warning(DeprecationWarning):
|
class DeprecationWarning(DeprecationWarning):
|
||||||
def __init__(self, msg, path, lineno):
|
def __init__(self, msg, path, lineno):
|
||||||
self.msg = msg
|
self.msg = msg
|
||||||
self.path = path
|
self.path = path
|
||||||
|
@ -66,7 +66,7 @@ def warn(msg, stacklevel=1, function=None):
|
||||||
if not filename:
|
if not filename:
|
||||||
filename = module
|
filename = module
|
||||||
path = py.path.local(filename)
|
path = py.path.local(filename)
|
||||||
warning = Warning(msg, path, lineno)
|
warning = DeprecationWarning(msg, path, lineno)
|
||||||
py.std.warnings.warn_explicit(warning, category=Warning,
|
py.std.warnings.warn_explicit(warning, category=Warning,
|
||||||
filename=str(warning.path),
|
filename=str(warning.path),
|
||||||
lineno=warning.lineno,
|
lineno=warning.lineno,
|
||||||
|
|
|
@ -188,7 +188,7 @@ class Config(object):
|
||||||
""" add a named group of options to the current testing session.
|
""" add a named group of options to the current testing session.
|
||||||
This function gets invoked during testing session initialization.
|
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)
|
group = self._parser.getgroup(groupname)
|
||||||
for opt in specs:
|
for opt in specs:
|
||||||
group._addoption_instance(opt)
|
group._addoption_instance(opt)
|
||||||
|
|
|
@ -1,39 +1,6 @@
|
||||||
import py
|
import py
|
||||||
|
|
||||||
class TestDistribution:
|
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):
|
def test_manytests_to_one_popen(self, testdir):
|
||||||
p1 = testdir.makepyfile("""
|
p1 = testdir.makepyfile("""
|
||||||
import py
|
import py
|
||||||
|
|
|
@ -2,23 +2,6 @@ import py
|
||||||
|
|
||||||
|
|
||||||
class TestConfigCmdlineParsing:
|
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):
|
def test_parser_addoption_default_env(self, testdir, monkeypatch):
|
||||||
import os
|
import os
|
||||||
config = testdir.Config()
|
config = testdir.Config()
|
||||||
|
|
|
@ -210,3 +210,60 @@ class TestDisabled:
|
||||||
def test_classlevel2(self): pass
|
def test_classlevel2(self): pass
|
||||||
""")
|
""")
|
||||||
reprec.assertoutcome(skipped=2)
|
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*",
|
||||||
|
])
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue