some minor compatibility issues wrt to the just released python2.7
--HG-- branch : trunk
This commit is contained in:
parent
223a04be27
commit
b28c439494
|
@ -37,6 +37,9 @@ New features
|
||||||
Bug fixes / Maintenance
|
Bug fixes / Maintenance
|
||||||
++++++++++++++++++++++++++
|
++++++++++++++++++++++++++
|
||||||
|
|
||||||
|
- make tests and the ``pytest_recwarn`` plugin in paricular fully compatible
|
||||||
|
to Python2.7 (if you use the ``recwarn`` funcarg warnings will be enabled so that
|
||||||
|
you can properly check for their existence in a cross-python manner).
|
||||||
- improve error messages if importing a test module failed (ImportError,
|
- improve error messages if importing a test module failed (ImportError,
|
||||||
import file mismatches, syntax errors)
|
import file mismatches, syntax errors)
|
||||||
- refine --pdb: ignore xfailed tests, unify its TB-reporting and
|
- refine --pdb: ignore xfailed tests, unify its TB-reporting and
|
||||||
|
|
|
@ -33,7 +33,7 @@ warning:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import py
|
import py
|
||||||
import os
|
import sys, os
|
||||||
|
|
||||||
def pytest_funcarg__recwarn(request):
|
def pytest_funcarg__recwarn(request):
|
||||||
"""Return a WarningsRecorder instance that provides these methods:
|
"""Return a WarningsRecorder instance that provides these methods:
|
||||||
|
@ -41,9 +41,16 @@ def pytest_funcarg__recwarn(request):
|
||||||
* ``pop(category=None)``: return last warning matching the category.
|
* ``pop(category=None)``: return last warning matching the category.
|
||||||
* ``clear()``: clear list of warnings
|
* ``clear()``: clear list of warnings
|
||||||
"""
|
"""
|
||||||
warnings = WarningsRecorder()
|
if sys.version_info >= (2,7):
|
||||||
request.addfinalizer(warnings.finalize)
|
import warnings
|
||||||
return warnings
|
oldfilters = warnings.filters[:]
|
||||||
|
warnings.simplefilter('default')
|
||||||
|
def reset_filters():
|
||||||
|
warnings.filters[:] = oldfilters
|
||||||
|
request.addfinalizer(reset_filters)
|
||||||
|
wrec = WarningsRecorder()
|
||||||
|
request.addfinalizer(wrec.finalize)
|
||||||
|
return wrec
|
||||||
|
|
||||||
def pytest_namespace():
|
def pytest_namespace():
|
||||||
return {'deprecated_call': deprecated_call}
|
return {'deprecated_call': deprecated_call}
|
||||||
|
|
|
@ -341,7 +341,7 @@ def test_deindent():
|
||||||
lines = deindent(source.splitlines())
|
lines = deindent(source.splitlines())
|
||||||
assert lines == ['', 'def f():', ' def g():', ' pass', ' ']
|
assert lines == ['', 'def f():', ' def g():', ' pass', ' ']
|
||||||
|
|
||||||
@py.test.mark.xfail
|
@py.test.mark.xfail("sys.version_info[:2] != (2,7)")
|
||||||
def test_source_of_class_at_eof_without_newline(tmpdir):
|
def test_source_of_class_at_eof_without_newline(tmpdir):
|
||||||
# this test fails because the implicit inspect.getsource(A) below
|
# this test fails because the implicit inspect.getsource(A) below
|
||||||
# does not return the "x = 1" last line.
|
# does not return the "x = 1" last line.
|
||||||
|
|
|
@ -4,7 +4,7 @@ mypath = py.path.local(__file__).new(ext=".py")
|
||||||
def test_forwarding_to_warnings_module():
|
def test_forwarding_to_warnings_module():
|
||||||
py.test.deprecated_call(py.log._apiwarn, "1.3", "..")
|
py.test.deprecated_call(py.log._apiwarn, "1.3", "..")
|
||||||
|
|
||||||
def test_apiwarn_functional():
|
def test_apiwarn_functional(recwarn):
|
||||||
capture = py.io.StdCapture()
|
capture = py.io.StdCapture()
|
||||||
py.log._apiwarn("x.y.z", "something", stacklevel=1)
|
py.log._apiwarn("x.y.z", "something", stacklevel=1)
|
||||||
out, err = capture.reset()
|
out, err = capture.reset()
|
||||||
|
@ -15,7 +15,7 @@ def test_apiwarn_functional():
|
||||||
exp = "%s:%s" % (mypath, lno)
|
exp = "%s:%s" % (mypath, lno)
|
||||||
assert err.find(exp) != -1
|
assert err.find(exp) != -1
|
||||||
|
|
||||||
def test_stacklevel():
|
def test_stacklevel(recwarn):
|
||||||
def f():
|
def f():
|
||||||
py.log._apiwarn("x", "some", stacklevel=2)
|
py.log._apiwarn("x", "some", stacklevel=2)
|
||||||
# 3
|
# 3
|
||||||
|
@ -27,7 +27,7 @@ def test_stacklevel():
|
||||||
warning = str(err)
|
warning = str(err)
|
||||||
assert warning.find(":%s" % lno) != -1
|
assert warning.find(":%s" % lno) != -1
|
||||||
|
|
||||||
def test_stacklevel_initpkg_with_resolve(testdir):
|
def test_stacklevel_initpkg_with_resolve(testdir, recwarn):
|
||||||
testdir.makepyfile(modabc="""
|
testdir.makepyfile(modabc="""
|
||||||
import py
|
import py
|
||||||
def f():
|
def f():
|
||||||
|
@ -49,7 +49,7 @@ def test_stacklevel_initpkg_with_resolve(testdir):
|
||||||
loc = 'test_stacklevel_initpkg_with_resolve.py:2'
|
loc = 'test_stacklevel_initpkg_with_resolve.py:2'
|
||||||
assert warning.find(loc) != -1
|
assert warning.find(loc) != -1
|
||||||
|
|
||||||
def test_stacklevel_initpkg_no_resolve():
|
def test_stacklevel_initpkg_no_resolve(recwarn):
|
||||||
def f():
|
def f():
|
||||||
py.log._apiwarn("x", "some", stacklevel="apipkg")
|
py.log._apiwarn("x", "some", stacklevel="apipkg")
|
||||||
capture = py.io.StdCapture()
|
capture = py.io.StdCapture()
|
||||||
|
@ -60,7 +60,7 @@ def test_stacklevel_initpkg_no_resolve():
|
||||||
assert warning.find(":%s" % lno) != -1
|
assert warning.find(":%s" % lno) != -1
|
||||||
|
|
||||||
|
|
||||||
def test_function():
|
def test_function(recwarn):
|
||||||
capture = py.io.StdCapture()
|
capture = py.io.StdCapture()
|
||||||
py.log._apiwarn("x.y.z", "something", function=test_function)
|
py.log._apiwarn("x.y.z", "something", function=test_function)
|
||||||
out, err = capture.reset()
|
out, err = capture.reset()
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import py
|
import py
|
||||||
from py._plugin.pytest_recwarn import WarningsRecorder
|
from py._plugin.pytest_recwarn import WarningsRecorder
|
||||||
|
|
||||||
def test_WarningRecorder():
|
def test_WarningRecorder(recwarn):
|
||||||
showwarning = py.std.warnings.showwarning
|
showwarning = py.std.warnings.showwarning
|
||||||
rec = WarningsRecorder()
|
rec = WarningsRecorder()
|
||||||
assert py.std.warnings.showwarning != showwarning
|
assert py.std.warnings.showwarning != showwarning
|
||||||
|
|
|
@ -23,10 +23,7 @@ def test_invoke_compile(recwarn, monkeypatch):
|
||||||
monkeypatch.setattr(py.builtin.builtins, 'compile', None)
|
monkeypatch.setattr(py.builtin.builtins, 'compile', None)
|
||||||
py.magic.invoke(compile=True)
|
py.magic.invoke(compile=True)
|
||||||
try:
|
try:
|
||||||
co = compile("""if 1:
|
co = compile("def f(): return 1\n", '', 'exec')
|
||||||
def f():
|
|
||||||
return 1
|
|
||||||
\n""", '', 'exec')
|
|
||||||
d = {}
|
d = {}
|
||||||
py.builtin.exec_(co, d)
|
py.builtin.exec_(co, d)
|
||||||
assert py.code.Source(d['f'])
|
assert py.code.Source(d['f'])
|
||||||
|
|
3
tox.ini
3
tox.ini
|
@ -3,6 +3,9 @@ changedir=testing
|
||||||
commands=
|
commands=
|
||||||
py.test --confcutdir=.. -rfsxX --junitxml=junit-{envname}.xml --tools-on-path []
|
py.test --confcutdir=.. -rfsxX --junitxml=junit-{envname}.xml --tools-on-path []
|
||||||
deps=pexpect
|
deps=pexpect
|
||||||
|
[testenv:py27]
|
||||||
|
distribute=True
|
||||||
|
basepython=python2.7
|
||||||
[testenv:py26]
|
[testenv:py26]
|
||||||
basepython=python2.6
|
basepython=python2.6
|
||||||
[testenv:doc]
|
[testenv:doc]
|
||||||
|
|
Loading…
Reference in New Issue