[py-svn] py-trunk commit 6d3330c22593: some minor compatibility issues wrt to the just released python2.7

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Sun Jul 4 22:13:56 CEST 2010


# HG changeset patch -- Bitbucket.org
# Project py-trunk
# URL http://bitbucket.org/hpk42/py-trunk/overview
# User holger krekel <holger at merlinux.eu>
# Date 1278274392 -7200
# Node ID 6d3330c22593bd7ffd3436766f12b95fc863baae
# Parent  5b98ae122cbe8b64efd856e732d750ebb6b19d71
some minor compatibility issues wrt to the just released python2.7

--- a/testing/log/test_warning.py
+++ b/testing/log/test_warning.py
@@ -4,7 +4,7 @@ mypath = py.path.local(__file__).new(ext
 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
     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()

--- a/tox.ini
+++ b/tox.ini
@@ -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]

--- a/testing/code/test_source.py
+++ b/testing/code/test_source.py
@@ -341,7 +341,7 @@ def test_deindent():
     lines = deindent(source.splitlines())
     assert lines == ['', 'def f():', '    def g():', '        pass', '    ']
 
- at py.test.mark.xfail
+ at 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. 

--- a/testing/root/test_oldmagic.py
+++ b/testing/root/test_oldmagic.py
@@ -23,10 +23,7 @@ def test_invoke_compile(recwarn, monkeyp
     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']) 

--- a/CHANGELOG
+++ b/CHANGELOG
@@ -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 

--- a/testing/plugin/test_pytest_recwarn.py
+++ b/testing/plugin/test_pytest_recwarn.py
@@ -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

--- a/py/_plugin/pytest_recwarn.py
+++ b/py/_plugin/pytest_recwarn.py
@@ -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}



More information about the pytest-commit mailing list