Skip to content

Commit

Permalink
Merge pull request ipython#4632 from takluyver/testfunc
Browse files Browse the repository at this point in the history
Restore the ability to run tests from a function.
  • Loading branch information
ivanov committed Dec 4, 2013
2 parents ce0b6be + c8fc9c9 commit a1535a2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 20 deletions.
19 changes: 14 additions & 5 deletions IPython/testing/__init__.py
Expand Up @@ -13,16 +13,25 @@
#-----------------------------------------------------------------------------

# User-level entry point for testing
def test(all=False):
def test(**kwargs):
"""Run the entire IPython test suite.
For fine-grained control, you should use the :file:`iptest` script supplied
with the IPython installation."""
Any of the options for run_iptestall() may be passed as keyword arguments.
For example::
IPython.test(testgroups=['lib', 'config', 'utils'], fast=2)
will run those three sections of the test suite, using two processes.
"""

# Do the import internally, so that this function doesn't increase total
# import time
from .iptest import run_iptestall
run_iptestall(inc_slow=all)
from .iptestcontroller import run_iptestall, default_options
options = default_options()
for name, val in kwargs.items():
setattr(options, name, val)
run_iptestall(options)

# So nose doesn't try to run this as a test itself and we end up with an
# infinite test loop
Expand Down
37 changes: 22 additions & 15 deletions IPython/testing/iptestcontroller.py
Expand Up @@ -456,6 +456,27 @@ def find_code_units(self, morfs):
# Ensure that our exit code indicates failure
sys.exit(1)

argparser = argparse.ArgumentParser(description='Run IPython test suite')
argparser.add_argument('testgroups', nargs='*',
help='Run specified groups of tests. If omitted, run '
'all tests.')
argparser.add_argument('--all', action='store_true',
help='Include slow tests not run by default.')
argparser.add_argument('-j', '--fast', nargs='?', const=None, default=1, type=int,
help='Run test sections in parallel.')
argparser.add_argument('--xunit', action='store_true',
help='Produce Xunit XML results')
argparser.add_argument('--coverage', nargs='?', const=True, default=False,
help="Measure test coverage. Specify 'html' or "
"'xml' to get reports.")

def default_options():
"""Get an argparse Namespace object with the default arguments, to pass to
:func:`run_iptestall`.
"""
options = argparser.parse_args([])
options.extra_args = []
return options

def main():
# Arguments after -- should be passed through to nose. Argparse treats
Expand All @@ -470,21 +491,7 @@ def main():
to_parse = sys.argv[1:ix]
extra_args = sys.argv[ix+1:]

parser = argparse.ArgumentParser(description='Run IPython test suite')
parser.add_argument('testgroups', nargs='*',
help='Run specified groups of tests. If omitted, run '
'all tests.')
parser.add_argument('--all', action='store_true',
help='Include slow tests not run by default.')
parser.add_argument('-j', '--fast', nargs='?', const=None, default=1, type=int,
help='Run test sections in parallel.')
parser.add_argument('--xunit', action='store_true',
help='Produce Xunit XML results')
parser.add_argument('--coverage', nargs='?', const=True, default=False,
help="Measure test coverage. Specify 'html' or "
"'xml' to get reports.")

options = parser.parse_args(to_parse)
options = argparser.parse_args(to_parse)
options.extra_args = extra_args

run_iptestall(options)
Expand Down

0 comments on commit a1535a2

Please sign in to comment.