diff --git a/src/bin/sage-runtests b/src/bin/sage-runtests index 21953ece292..24affd7cce3 100755 --- a/src/bin/sage-runtests +++ b/src/bin/sage-runtests @@ -72,7 +72,7 @@ if __name__ == "__main__": parser.add_option("--randorder", type=int, metavar="SEED", help="randomize order of tests") parser.add_option("--global-iterations", "--global_iterations", type=int, default=0, help="repeat the whole testing process this many times") parser.add_option("--file-iterations", "--file_iterations", type=int, default=0, help="repeat each file this many times, stopping on the first failure") - parser.add_option("--environment", type=str, default=None, help="name of a module that provides the global environment for tests") + parser.add_option("--environment", type=str, default="sage.repl.ipython_kernel.all_jupyter", help="name of a module that provides the global environment for tests") parser.add_option("-i", "--initial", action="store_true", default=False, help="only show the first failure in each file") parser.add_option("--exitfirst", action="store_true", default=False, help="end the test run immediately after the first failure or unexpected exception") diff --git a/src/sage/doctest/control.py b/src/sage/doctest/control.py index f2dadaec131..1e8403f6057 100644 --- a/src/sage/doctest/control.py +++ b/src/sage/doctest/control.py @@ -99,6 +99,7 @@ def __init__(self, **kwds): self.randorder = None self.global_iterations = 1 # sage-runtests default is 0 self.file_iterations = 1 # sage-runtests default is 0 + self.environment = "sage.repl.ipython_kernel.all_jupyter" self.initial = False self.exitfirst = False self.force_lib = False @@ -497,6 +498,25 @@ def _repr_(self): """ return "DocTest Controller" + def load_environment(self): + """ + Return the module that provides the global environment. + + EXAMPLES:: + + sage: from sage.doctest.control import DocTestDefaults, DocTestController + sage: DC = DocTestController(DocTestDefaults(), []) + sage: 'BipartiteGraph' in DC.load_environment().__dict__ + True + sage: DC = DocTestController(DocTestDefaults(environment='sage.doctest.all'), []) + sage: 'BipartiteGraph' in DC.load_environment().__dict__ + False + sage: 'run_doctests' in DC.load_environment().__dict__ + True + """ + from importlib import import_module + return import_module(self.options.environment) + def load_stats(self, filename): """ Load stats from the most recent run(s). diff --git a/src/sage/doctest/forker.py b/src/sage/doctest/forker.py index 10303a894de..e0fa90254f5 100644 --- a/src/sage/doctest/forker.py +++ b/src/sage/doctest/forker.py @@ -88,7 +88,7 @@ -def init_sage(): +def init_sage(environment=None): """ Import the Sage library. @@ -1630,7 +1630,7 @@ def __init__(self, controller): """ self.controller = controller - init_sage() + init_sage(controller.options.environment) def serial_dispatch(self): """ @@ -2510,7 +2510,8 @@ def _run(self, runner, options, results): """ # Import Jupyter globals to doctest the Jupyter # implementation of widgets and interacts - import sage.repl.ipython_kernel.all_jupyter as sage_all + from importlib import import_module + sage_all = import_module(options.environment) dict_all = sage_all.__dict__ # Remove '__package__' item from the globals since it is not # always in the globals in an actual Sage session.