From cbbbfcd1011a7127761663928056e230aecbe3f2 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Thu, 1 Aug 2013 15:38:03 +0200 Subject: [PATCH] fix collection imports for python2.5 --- _pytest/assertion/util.py | 6 +++++- testing/conftest.py | 2 +- testing/test_assertion.py | 14 ++++++++------ 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/_pytest/assertion/util.py b/_pytest/assertion/util.py index 611b330c0..ad8ed070f 100644 --- a/_pytest/assertion/util.py +++ b/_pytest/assertion/util.py @@ -4,7 +4,11 @@ import py try: from collections.abc import Sequence except ImportError: - from collections import Sequence + try: + from collections import Sequence + except ImportError: + Sequence = list + BuiltinAssertionError = py.builtin.builtins.AssertionError diff --git a/testing/conftest.py b/testing/conftest.py index 66019e939..b4c06e5ee 100644 --- a/testing/conftest.py +++ b/testing/conftest.py @@ -65,7 +65,7 @@ def pytest_generate_tests(metafunc): for val in l: metafunc.addcall(funcargs={name: val}) elif 'anypython' in metafunc.fixturenames: - for name in ('python2.4', 'python2.5', 'python2.6', + for name in ('python2.5', 'python2.6', 'python2.7', 'python3.2', "python3.3", 'pypy', 'jython'): metafunc.addcall(id=name, param=name) diff --git a/testing/test_assertion.py b/testing/test_assertion.py index 4ebb80305..8b98a7292 100644 --- a/testing/test_assertion.py +++ b/testing/test_assertion.py @@ -3,12 +3,6 @@ import sys import py, pytest import _pytest.assertion as plugin from _pytest.assertion import reinterpret, util -try: - from collections.abc import MutableSequence -except ImportError: - from collections import MutableSequence - - needsnewassert = pytest.mark.skipif("sys.version_info < (2,6)") @@ -122,6 +116,14 @@ class TestAssert_reprcompare: assert len(expl) > 1 def test_Sequence(self): + col = py.builtin._tryimport( + "collections.abc", + "collections", + "sys") + if not hasattr(col, "MutableSequence"): + pytest.skip("cannot import MutableSequence") + MutableSequence = col.MutableSequence + class TestSequence(MutableSequence): # works with a Sequence subclass def __init__(self, iterable): self.elements = list(iterable)