From d02eaa88817c634977ca857c1d54ac2494e49a1e Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Fri, 13 Apr 2012 12:41:02 +0200 Subject: [PATCH] fix a import strange loop that affects pypy test appsupport on python2.5 --- _pytest/assertion/oldinterpret.py | 3 +-- _pytest/assertion/reinterpret.py | 3 +-- _pytest/assertion/util.py | 1 + testing/test_assertinterpret.py | 15 +++++++++++++++ 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/_pytest/assertion/oldinterpret.py b/_pytest/assertion/oldinterpret.py index 3ca12ec2b..a90c91859 100644 --- a/_pytest/assertion/oldinterpret.py +++ b/_pytest/assertion/oldinterpret.py @@ -1,8 +1,7 @@ import py import sys, inspect from compiler import parse, ast, pycodegen -from _pytest.assertion.util import format_explanation -from _pytest.assertion.reinterpret import BuiltinAssertionError +from _pytest.assertion.util import format_explanation, BuiltinAssertionError passthroughex = py.builtin._sysex diff --git a/_pytest/assertion/reinterpret.py b/_pytest/assertion/reinterpret.py index 6e9465d8a..b0d5a6689 100644 --- a/_pytest/assertion/reinterpret.py +++ b/_pytest/assertion/reinterpret.py @@ -1,7 +1,6 @@ import sys import py - -BuiltinAssertionError = py.builtin.builtins.AssertionError +from _pytest.assertion.util import BuiltinAssertionError class AssertionError(BuiltinAssertionError): def __init__(self, *args): diff --git a/_pytest/assertion/util.py b/_pytest/assertion/util.py index a85ed99f7..c7ef6dd81 100644 --- a/_pytest/assertion/util.py +++ b/_pytest/assertion/util.py @@ -2,6 +2,7 @@ import py +BuiltinAssertionError = py.builtin.builtins.AssertionError # The _reprcompare attribute on the util module is used by the new assertion # interpretation code and assertion rewriter to detect this plugin was diff --git a/testing/test_assertinterpret.py b/testing/test_assertinterpret.py index fc456c636..bc7c55616 100644 --- a/testing/test_assertinterpret.py +++ b/testing/test_assertinterpret.py @@ -322,3 +322,18 @@ def test_assert_raises_in_nonzero_of_object_pytest_issue10(): e = exvalue() s = str(e) assert " < 0" in s + +@py.test.mark.skipif("sys.version_info >= (2,6)") +def test_oldinterpret_importation(): + # we had a cyclic import there + # requires pytest on sys.path + res = py.std.subprocess.call([ + py.std.sys.executable, '-c', str(py.code.Source(""" + try: + from _pytest.assertion.newinterpret import interpret + except ImportError: + from _pytest.assertion.oldinterpret import interpret + """)) + ]) + + assert res == 0