Bug 1185761 - [mochitest] Allow boolean values to --keep-open for overriding the default, r=ted

Most of the time the default is to close the browser after tests run. And that can be overridden with
--keep-open. But in some corner cases, the default is to leave the browser open after tests have run.
In these cases, it is not currently possible to override.

This patch allows the syntax --keep-open or --keep-open=false, the latter overrides the edge case
default.

--HG--
extra : commitid : 52IHmZFn1uj
extra : rebase_source : 50ce300ccb08f87e5c9337b945d538c0a17ac04d
This commit is contained in:
Andrew Halberstadt 2015-08-06 17:40:54 -04:00
parent 314bac7460
commit e318244a76
3 changed files with 18 additions and 10 deletions

View File

@ -339,9 +339,12 @@ class MochitestRunner(MozbuildObject):
manifest.tests.extend(tests)
options.manifestFile = manifest
# XXX why is this such a special case?
if len(tests) == 1 and options.closeWhenDone and suite == 'plain':
options.closeWhenDone = False
# When developing mochitest-plain tests, it's often useful to be able to
# refresh the page to pick up modifications. Therefore leave the browser
# open if only running a single mochitest-plain test. This behaviour can
# be overridden by passing in --keep-open=false.
if len(tests) == 1 and options.keep_open is None and suite == 'plain':
options.keep_open = True
# We need this to enable colorization of output.
self.log_manager.enable_unstructured()

View File

@ -4,6 +4,7 @@
from abc import ABCMeta, abstractmethod, abstractproperty
from argparse import ArgumentParser, SUPPRESS
from distutils.util import strtobool
from urlparse import urlparse
import os
import tempfile
@ -66,10 +67,12 @@ class MochitestArguments(ArgumentContainer):
"(to run recursively). If omitted, the entire suite is run.",
}],
[["--keep-open"],
{"action": "store_false",
"dest": "closeWhenDone",
"default": True,
"help": "Always keep the browser open after tests complete.",
{"nargs": "?",
"type": strtobool,
"const": "true",
"default": None,
"help": "Always keep the browser open after tests complete. Or always close the "
"browser with --keep-open=false",
}],
[["--appname"],
{"dest": "app",

View File

@ -332,7 +332,7 @@ class MochitestServer(object):
if isinstance(options, Namespace):
options = vars(options)
self._log = logger
self._closeWhenDone = options['closeWhenDone']
self._keep_open = bool(options['keep_open'])
self._utilityPath = options['utilityPath']
self._xrePath = options['xrePath']
self._profileDir = options['profilePath']
@ -390,7 +390,7 @@ class MochitestServer(object):
"server": self.webServer,
"testPrefix": self.testPrefix,
"displayResults": str(
not self._closeWhenDone).lower()},
self._keep_open).lower()},
"-f",
os.path.join(
SCRIPT_DIR,
@ -594,7 +594,7 @@ class MochitestUtilsMixin(object):
self.urlOpts.append("timeout=%d" % options.timeout)
if options.maxTimeouts:
self.urlOpts.append("maxTimeouts=%d" % options.maxTimeouts)
if options.closeWhenDone:
if not options.keep_open:
self.urlOpts.append("closeWhenDone=1")
if options.webapprtContent:
self.urlOpts.append("testRoot=webapprtContent")
@ -2531,6 +2531,8 @@ class Mochitest(MochitestUtilsMixin):
d = dict((k, v) for k, v in options.__dict__.items() if (v is None) or
isinstance(v,(basestring,numbers.Number)))
d['testRoot'] = self.testRoot
if not options.keep_open:
d['closeWhenDone'] = '1'
content = json.dumps(d)
with open(os.path.join(options.profilePath, "testConfig.js"), "w") as config: