From 2229d2d9470ab5bb882d85f6a92367be6419322f Mon Sep 17 00:00:00 2001 From: holger krekel Date: Wed, 19 May 2010 16:42:22 +0200 Subject: [PATCH] revert 1735 - fix issue95 differently: just shift the offending zlib import (and others) to happen when they are actually needed --HG-- branch : trunk --- CHANGELOG | 3 +++ py/_plugin/pytest_genscript.py | 14 ++++++------- py/_test/pluginmanager.py | 7 ------- testing/plugin/test_pytest_genscript.py | 1 - testing/test_pluginmanager.py | 26 ------------------------- 5 files changed, 10 insertions(+), 41 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 40444fb82..e3c12aaca 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -6,6 +6,9 @@ Changes between 1.3.0 and 1.3.1 to the underlying capturing functionality to avoid race conditions). +- fix issue95: late-import zlib so that it's not required + for general py.test startup. + - make py.test.cmdline.main() return the exitstatus instead of raising (which is still done by py.cmdline.pytest()) and make it so that py.test.cmdline.main() can be called diff --git a/py/_plugin/pytest_genscript.py b/py/_plugin/pytest_genscript.py index 68ff9b08f..531c8795f 100755 --- a/py/_plugin/pytest_genscript.py +++ b/py/_plugin/pytest_genscript.py @@ -4,14 +4,7 @@ generate standalone test script to be distributed along with an application. """ import os -import zlib -import base64 import sys -try: - import pickle -except Importerror: - import cPickle as pickle - def pytest_addoption(parser): group = parser.getgroup("debugconfig") group.addoption("--genscript", action="store", default=None, @@ -30,6 +23,13 @@ def pytest_configure(config): raise SystemExit(0) def main(pybasedir, outfile, infile): + import base64 + import zlib + try: + import pickle + except Importerror: + import cPickle as pickle + outfile = str(outfile) infile = str(infile) assert os.path.isabs(outfile) diff --git a/py/_test/pluginmanager.py b/py/_test/pluginmanager.py index 8b90c8b1c..d1b673421 100644 --- a/py/_test/pluginmanager.py +++ b/py/_test/pluginmanager.py @@ -140,13 +140,6 @@ class PluginManager(object): except py.test.skip.Exception: e = py.std.sys.exc_info()[1] self._hints.append("skipped plugin %r: %s" %((modname, e.msg))) - except ImportError: - e = py.std.sys.exc_info()[1] - if "zlib" in str(e) and modname == "pytest_genscript": - self._hints.append("skipped plugin %r: failed to import %r" %( - (modname, str(e)))) - else: - raise else: check_old_use(mod, modname) self.register(mod) diff --git a/testing/plugin/test_pytest_genscript.py b/testing/plugin/test_pytest_genscript.py index 2f657fb95..c421460fc 100644 --- a/testing/plugin/test_pytest_genscript.py +++ b/testing/plugin/test_pytest_genscript.py @@ -37,4 +37,3 @@ def test_rundist(testdir, pytestconfig, standalone): result.stdout.fnmatch_lines([ "*1 passed*", ]) - diff --git a/testing/test_pluginmanager.py b/testing/test_pluginmanager.py index f903e7e94..425333768 100644 --- a/testing/test_pluginmanager.py +++ b/testing/test_pluginmanager.py @@ -489,29 +489,3 @@ class TestHookRelay: res = mcm.hello(arg=3) assert res == 4 -def test_pluginmanager_import_error_zlib(testdir): - p = testdir.makepyfile(""" - try: - import builtins - except ImportError: - import __builtin__ as builtins - oldimport = builtins.__import__ - - def import_(name, *args): - #print "import", name, "start" - if name == "zlib": - raise ImportError("zlib") - mod = oldimport(name, *args) - #print "import", name, "successful" - return mod - - if __name__ == "__main__": - builtins.__import__ = import_ - import py - py.test.cmdline.main(["--traceconfig"]) - """) - result = testdir.runpython(p) - result.stdout.fnmatch_lines([ - "*skipped plugin*genscript*import*zlib*", - ]) -