diff -r 540b022ae7a9 Lib/test/regrtest.py --- a/Lib/test/regrtest.py Thu Nov 06 15:33:30 2014 +0100 +++ b/Lib/test/regrtest.py Thu Nov 06 15:58:55 2014 +0100 @@ -269,6 +269,8 @@ def _create_parser(): group.add_argument('-f', '--fromfile', metavar='FILE', help='read names of tests to run from a file.' + more_details) + group.add_argument('-c', '--changed', action='store_true', + help='select tests marked as changed by Mercurial') group.add_argument('-x', '--exclude', action='store_true', help='arguments are tests to *exclude*') group.add_argument('-s', '--single', action='store_true', @@ -361,7 +363,7 @@ def _parse_args(args, **kwargs): findleaks=False, use_resources=None, trace=False, coverdir='coverage', runleaks=False, huntrleaks=False, verbose2=False, print_slow=False, random_seed=None, use_mp=None, verbose3=False, forever=False, - header=False, failfast=False, match_tests=None) + header=False, failfast=False, match_tests=None, changed=False) for k, v in kwargs.items(): if not hasattr(ns, k): raise TypeError('%r is an invalid keyword argument ' @@ -375,6 +377,8 @@ def _parse_args(args, **kwargs): if ns.single and ns.fromfile: parser.error("-s and -f don't go together!") + if ns.single and ns.changed: + parser.error("-s and -c don't go together!") if ns.use_mp and ns.trace: parser.error("-T and -j don't go together!") if ns.use_mp and ns.findleaks: @@ -582,6 +586,19 @@ def main(tests=None, **kwargs): if guts and not guts[0].startswith('#'): tests.extend(guts) + if ns.changed: + from subprocess import Popen, PIPE, DEVNULL + env = os.environ.copy() + env['HGPLAIN'] = '1' + prefix = os.path.join('Lib', 'test') + os.path.sep + with Popen(['hg', 'status', '-mn'], stdout=PIPE, stderr=DEVNULL, env=env) as p: + tests = p.communicate()[0] + tests = [t[len(prefix):-3] for t in tests.decode().splitlines() + if t.startswith(prefix + 'test_')] + if not tests: + print("No test files changed or not running from checkout, exiting.") + sys.exit(0) + # Strip .py extensions. removepy(ns.args) removepy(tests)