blob: 9e93f19d2588a0711e65e9133a7332cc3718ca04 [file] [log] [blame]
#!/usr/bin/env python
# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
'''Standalone test driver.
Note that this is tested indirectly by
import argparse
import logging
import os
import pickle
import sys
import factory_common # pylint: disable=W0611
from cros.factory.goofy import invocation
from cros.factory.test import factory
from cros.factory.utils import file_utils
def RunPyTest(name, args):
'''Runs a pytest.
name: The name of the test within the pytests module (e.g.,
args: The argument dictionary.
True if the test passed.
with file_utils.UnopenedTemporaryFile(prefix='results') as results:
info = invocation.PyTestInfo(None, None, name, args, results)
return pickle.load(open(results))[0] == factory.TestState.PASSED
def main():
# Unbuffer stdout
sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
parser = argparse.ArgumentParser()
# TODO(jsalz): Read the test's ARGS and use argparse to parse
# test-specific arguments and print test-specific help.
help='''Dictionary of arguments, e.g., "{'foo': 'bar'}"''')
parser.add_argument('--verbose', '-v', action='count')
'pytest', metavar='TEST_NAME',
help='Name of the pytest within the pytests module, e.g., '
args = parser.parse_args()
logging.basicConfig(level=(logging.INFO - 10 * (args.verbose or 0)))
passed = RunPyTest(args.pytest, eval(args.args) if args.args else {})
sys.exit(0 if passed else 1)
if __name__ == '__main__':