diff --git a/IPython/testing/decorators.py b/IPython/testing/decorators.py index a15e1b3..fca1b15 100644 --- a/IPython/testing/decorators.py +++ b/IPython/testing/decorators.py @@ -55,9 +55,6 @@ import unittest # This is Michele Simionato's decorator module, kept verbatim. from IPython.external.decorator import decorator, update_wrapper -# Our own modules -import nosepatch # monkeypatch nose - # We already have python3-compliant code for parametric tests if sys.version[0]=='2': from _paramtestpy2 import parametric, ParametricTestCase diff --git a/IPython/testing/iptest.py b/IPython/testing/iptest.py index 84a7984..e4bc780 100644 --- a/IPython/testing/iptest.py +++ b/IPython/testing/iptest.py @@ -22,6 +22,7 @@ from __future__ import absolute_import # Module imports #----------------------------------------------------------------------------- +# Stdlib import os import os.path as path import signal @@ -31,9 +32,16 @@ import tempfile import time import warnings +# Note: monkeypatch! +# We need to monkeypatch a small problem in nose itself first, before importing +# it for actual use. This should get into nose upstream, but its release cycle +# is slow and we need it for our parametric tests to work correctly. +from . import nosepatch +# Now, proceed to import nose itself import nose.plugins.builtin from nose.core import TestProgram +# Our own imports from IPython.utils import genutils from IPython.utils.platutils import find_cmd, FindCmdError from . import globalipapp diff --git a/IPython/testing/ipunittest.py b/IPython/testing/ipunittest.py index 4380dbf..fe57e4e 100644 --- a/IPython/testing/ipunittest.py +++ b/IPython/testing/ipunittest.py @@ -46,9 +46,6 @@ try: except: from ._doctest26 import TestResults -# Our own, a nose monkeypatch -from . import nosepatch - # We already have python3-compliant code for parametric tests if sys.version[0]=='2': from ._paramtestpy2 import ParametricTestCase diff --git a/IPython/testing/tools.py b/IPython/testing/tools.py index 5b0d1e0..49c0126 100644 --- a/IPython/testing/tools.py +++ b/IPython/testing/tools.py @@ -31,7 +31,14 @@ import re import sys import tempfile -import nose.tools as nt +try: + # These tools are used by parts of the runtime, so we make the nose + # dependency optional at this point. Nose is a hard dependency to run the + # test suite, but NOT to use ipython itself. + import nose.tools as nt + has_nose = True +except ImportError: + has_nose = False from IPython.utils import genutils, platutils @@ -47,8 +54,9 @@ def %(name)s(*a,**kw): return nt.%(name)s(*a,**kw) """ -for _x in [a for a in dir(nt) if a.startswith('assert')]: - exec _tpl % dict(name=_x) +if has_nose: + for _x in [a for a in dir(nt) if a.startswith('assert')]: + exec _tpl % dict(name=_x) #----------------------------------------------------------------------------- # Functions and classes @@ -228,6 +236,8 @@ def ipexec_validate(fname, expected_out, expected_err=None, None """ + import nose.tools as nt + out, err = ipexec(fname) nt.assert_equals(out.strip(), expected_out.strip()) if expected_err: