From f194b16a09dfaca18fdf50061060efd28a4f4538 Mon Sep 17 00:00:00 2001 From: Floris Bruynooghe Date: Mon, 6 Sep 2010 19:46:58 +0100 Subject: [PATCH] Don't import difflib and pprint up-front Builtin plugins need to keep their import time to a minimum. Therefore it's better to delay importing till you really need it, i.e. use py.std.* in this case. --HG-- branch : trunk --- py/_plugin/pytest_assertion.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/py/_plugin/pytest_assertion.py b/py/_plugin/pytest_assertion.py index 5e9c2b81b..1e5452f07 100644 --- a/py/_plugin/pytest_assertion.py +++ b/py/_plugin/pytest_assertion.py @@ -1,6 +1,3 @@ -import difflib -import pprint - import py import sys @@ -44,7 +41,7 @@ def pytest_assert_compare(op, left, right): isdict = lambda x: isinstance(x, dict) if istext(left): explanation += [line.strip('\n') for line in - difflib.ndiff(left.splitlines(), right.splitlines())] + py.std.difflib.ndiff(left.splitlines(), right.splitlines())] elif issquence(left): explanation += _compare_eq_sequence(left, right) elif isdict(left): @@ -73,5 +70,5 @@ def _compare_eq_sequence(left, right): def _pprint_diff(left, right): """Make explanation using pprint and difflib""" return [line.strip('\n') for line in - difflib.ndiff(pprint.pformat(left).splitlines(), - pprint.pformat(right).splitlines())] + py.std.difflib.ndiff(py.std.pprint.pformat(left).splitlines(), + py.std.pprint.pformat(right).splitlines())]