some minor compatibility issues wrt to the just released python2.7

--HG--
branch : trunk
This commit is contained in:
holger krekel 2010-07-04 22:13:12 +02:00
parent 223a04be27
commit b28c439494
7 changed files with 25 additions and 15 deletions

View File

@ -37,6 +37,9 @@ New features
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,
import file mismatches, syntax errors)
- refine --pdb: ignore xfailed tests, unify its TB-reporting and

View File

@ -33,7 +33,7 @@ warning:
"""
import py
import os
import sys, os
def pytest_funcarg__recwarn(request):
"""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.
* ``clear()``: clear list of warnings
"""
warnings = WarningsRecorder()
request.addfinalizer(warnings.finalize)
return warnings
if sys.version_info >= (2,7):
import 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():
return {'deprecated_call': deprecated_call}

View File

@ -341,7 +341,7 @@ def test_deindent():
lines = deindent(source.splitlines())
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):
# this test fails because the implicit inspect.getsource(A) below
# does not return the "x = 1" last line.

View File

@ -4,7 +4,7 @@ mypath = py.path.local(__file__).new(ext=".py")
def test_forwarding_to_warnings_module():
py.test.deprecated_call(py.log._apiwarn, "1.3", "..")
def test_apiwarn_functional():
def test_apiwarn_functional(recwarn):
capture = py.io.StdCapture()
py.log._apiwarn("x.y.z", "something", stacklevel=1)
out, err = capture.reset()
@ -15,7 +15,7 @@ def test_apiwarn_functional():
exp = "%s:%s" % (mypath, lno)
assert err.find(exp) != -1
def test_stacklevel():
def test_stacklevel(recwarn):
def f():
py.log._apiwarn("x", "some", stacklevel=2)
# 3
@ -27,7 +27,7 @@ def test_stacklevel():
warning = str(err)
assert warning.find(":%s" % lno) != -1
def test_stacklevel_initpkg_with_resolve(testdir):
def test_stacklevel_initpkg_with_resolve(testdir, recwarn):
testdir.makepyfile(modabc="""
import py
def f():
@ -49,7 +49,7 @@ def test_stacklevel_initpkg_with_resolve(testdir):
loc = 'test_stacklevel_initpkg_with_resolve.py:2'
assert warning.find(loc) != -1
def test_stacklevel_initpkg_no_resolve():
def test_stacklevel_initpkg_no_resolve(recwarn):
def f():
py.log._apiwarn("x", "some", stacklevel="apipkg")
capture = py.io.StdCapture()
@ -60,7 +60,7 @@ def test_stacklevel_initpkg_no_resolve():
assert warning.find(":%s" % lno) != -1
def test_function():
def test_function(recwarn):
capture = py.io.StdCapture()
py.log._apiwarn("x.y.z", "something", function=test_function)
out, err = capture.reset()

View File

@ -1,7 +1,7 @@
import py
from py._plugin.pytest_recwarn import WarningsRecorder
def test_WarningRecorder():
def test_WarningRecorder(recwarn):
showwarning = py.std.warnings.showwarning
rec = WarningsRecorder()
assert py.std.warnings.showwarning != showwarning

View File

@ -23,10 +23,7 @@ def test_invoke_compile(recwarn, monkeypatch):
monkeypatch.setattr(py.builtin.builtins, 'compile', None)
py.magic.invoke(compile=True)
try:
co = compile("""if 1:
def f():
return 1
\n""", '', 'exec')
co = compile("def f(): return 1\n", '', 'exec')
d = {}
py.builtin.exec_(co, d)
assert py.code.Source(d['f'])

View File

@ -3,6 +3,9 @@ changedir=testing
commands=
py.test --confcutdir=.. -rfsxX --junitxml=junit-{envname}.xml --tools-on-path []
deps=pexpect
[testenv:py27]
distribute=True
basepython=python2.7
[testenv:py26]
basepython=python2.6
[testenv:doc]