diff --git a/IPython/testing/iptest.py b/IPython/testing/iptest.py index 14f8eba..50f9bee 100644 --- a/IPython/testing/iptest.py +++ b/IPython/testing/iptest.py @@ -61,7 +61,7 @@ def main(): # plugin needs to be gone through with a fine # toothed comb to find what is causing the problem. # '--with-ipdoctest', - '--doctest-tests','--doctest-extension=txt', + '--ipdoctest-tests','--ipdoctest-extension=txt', '--detailed-errors', # We add --exe because of setuptools' imbecility (it @@ -81,11 +81,13 @@ def main(): (':' in arg and '.py' in arg): has_tests = True break + # If nothing was specifically requested, test full IPython if not has_tests: argv.append('IPython') - # Construct list of plugins, omitting the existing doctest plugin. + # Construct list of plugins, omitting the existing doctest plugin, which + # ours replaces (and extends). plugins = [IPythonDoctest(EXCLUDE)] for p in nose.plugins.builtin.plugins: plug = p() diff --git a/IPython/testing/plugin/ipdoctest.py b/IPython/testing/plugin/ipdoctest.py index 64e6a2c..7093d06 100644 --- a/IPython/testing/plugin/ipdoctest.py +++ b/IPython/testing/plugin/ipdoctest.py @@ -123,6 +123,13 @@ class ipnsdict(dict): def start_ipython(): """Start a global IPython shell, which we need for IPython-specific syntax. """ + + # This function should only ever run once! + if hasattr(start_ipython,'already_called'): + return + start_ipython.already_called = True + + # Ok, first time we're called, go ahead import new import IPython @@ -691,6 +698,7 @@ class ExtensionDoctest(doctests.Doctest): to exclude any filename which matches them from inclusion in the test suite (using pattern.search(), NOT pattern.match() ). """ + if exclude_patterns is None: exclude_patterns = [] self.exclude_patterns = map(re.compile,exclude_patterns) @@ -836,11 +844,30 @@ class IPythonDoctest(ExtensionDoctest): optionflags=optionflags, checker=self.checker) - def configure(self, options, config): + def options(self, parser, env=os.environ): + Plugin.options(self, parser, env) + parser.add_option('--ipdoctest-tests', action='store_true', + dest='ipdoctest_tests', + default=env.get('NOSE_IPDOCTEST_TESTS',True), + help="Also look for doctests in test modules. " + "Note that classes, methods and functions should " + "have either doctests or non-doctest tests, " + "not both. [NOSE_IPDOCTEST_TESTS]") + parser.add_option('--ipdoctest-extension', action="append", + dest="ipdoctestExtension", + help="Also look for doctests in files with " + "this extension [NOSE_IPDOCTEST_EXTENSION]") + # Set the default as a list, if given in env; otherwise + # an additional value set on the command line will cause + # an error. + env_setting = env.get('NOSE_IPDOCTEST_EXTENSION') + if env_setting is not None: + parser.set_defaults(ipdoctestExtension=tolist(env_setting)) + def configure(self, options, config): Plugin.configure(self, options, config) - self.doctest_tests = options.doctest_tests - self.extension = tolist(options.doctestExtension) + self.doctest_tests = options.ipdoctest_tests + self.extension = tolist(options.ipdoctestExtension) self.parser = IPDocTestParser() self.finder = DocTestFinder(parser=self.parser) diff --git a/IPython/testing/plugin/show_refs.py b/IPython/testing/plugin/show_refs.py index 11a441f..cbba10f 100644 --- a/IPython/testing/plugin/show_refs.py +++ b/IPython/testing/plugin/show_refs.py @@ -6,8 +6,9 @@ This is used by a companion test case. import gc class C(object): - def __del__(self): - print 'deleting object...' + def __del__(self): + pass + #print 'deleting object...' # dbg c = C() diff --git a/IPython/testing/plugin/test_refs.py b/IPython/testing/plugin/test_refs.py index ae9ba41..599bdcc 100644 --- a/IPython/testing/plugin/test_refs.py +++ b/IPython/testing/plugin/test_refs.py @@ -39,13 +39,10 @@ def doctest_ivars(): Out[6]: 1 """ -@dec.skip_doctest +#@dec.skip_doctest def doctest_refs(): """DocTest reference holding issues when running scripts. In [32]: run show_refs.py c referrers: [] - - In [33]: map(type,gc.get_referrers(c)) - Out[33]: [] """ diff --git a/IPython/tests/obj_del.py b/IPython/tests/obj_del.py index 089182e..fa84bf9 100644 --- a/IPython/tests/obj_del.py +++ b/IPython/tests/obj_del.py @@ -26,7 +26,7 @@ import sys class A(object): def __del__(self): - print 'object A deleted' + print 'obj_del.py: object A deleted' a = A() diff --git a/IPython/tests/tclass.py b/IPython/tests/tclass.py index 1e8e1dd..5f3bb24 100644 --- a/IPython/tests/tclass.py +++ b/IPython/tests/tclass.py @@ -16,11 +16,12 @@ class C(object): self.name = name def __del__(self): - print 'Deleting object:',self.name + print 'tclass.py: deleting object:',self.name try: name = sys.argv[1] except IndexError: pass else: - c = C(name) + if name.startswith('C'): + c = C(name) diff --git a/IPython/tests/test_magic.py b/IPython/tests/test_magic.py index eeb175c..4878710 100644 --- a/IPython/tests/test_magic.py +++ b/IPython/tests/test_magic.py @@ -37,7 +37,7 @@ def test_rehashx(): def doctest_run_ns(): """Classes declared %run scripts must be instantiable afterwards. - In [11]: run tclass + In [11]: run tclass foo In [12]: isinstance(f(),foo) Out[12]: True @@ -47,12 +47,10 @@ def doctest_run_ns(): def doctest_run_ns2(): """Classes declared %run scripts must be instantiable afterwards. - In [3]: run tclass.py + In [4]: run tclass C-first_pass - In [4]: run tclass first_pass - - In [5]: run tclass second_pass - Deleting object: first_pass + In [5]: run tclass C-second_pass + tclass.py: deleting object: C-first_pass """ @@ -85,7 +83,7 @@ def test_obj_del(): test_dir = os.path.dirname(__file__) del_file = os.path.join(test_dir,'obj_del.py') out = _ip.IP.getoutput('ipython %s' % del_file) - nt.assert_equals(out,'object A deleted') + nt.assert_equals(out,'obj_del.py: object A deleted') def test_shist():