本文整理汇总了Python中pyutilib.misc.Options.categories方法的典型用法代码示例。如果您正苦于以下问题:Python Options.categories方法的具体用法?Python Options.categories怎么用?Python Options.categories使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyutilib.misc.Options
的用法示例。
在下文中一共展示了Options.categories方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_test_suites
# 需要导入模块: from pyutilib.misc import Options [as 别名]
# 或者: from pyutilib.misc.Options import categories [as 别名]
def create_test_suites(filename=None, config=None, _globals=None, options=None):
if options is None: #pragma:nocover
options = Options()
#
# Add categories specified by the PYUTILIB_AUTOTEST_CATEGORIES
# or PYUTILIB_UNITTEST_CATEGORIES environments
#
if options is None or options.categories is None or len(
options.categories) == 0:
options.categories = set()
if 'PYUTILIB_AUTOTEST_CATEGORIES' in os.environ:
for cat in re.split(',',
os.environ['PYUTILIB_AUTOTEST_CATEGORIES']):
if cat != '':
options.categories.add(cat.strip())
elif 'PYUTILIB_UNITTEST_CATEGORIES' in os.environ:
for cat in re.split(',',
os.environ['PYUTILIB_UNITTEST_CATEGORIES']):
if cat != '':
options.categories.add(cat.strip())
#
if not filename is None:
if options.currdir is None:
options.currdir = dirname(abspath(filename)) + os.sep
#
ep = ExtensionPoint(plugins.ITestParser)
ftype = os.path.splitext(filename)[1]
if not ftype == '':
ftype = ftype[1:]
service = ep.service(ftype)
if service is None:
raise IOError(
"Unknown file type. Cannot load test configuration from file '%s'"
% filename)
config = service.load_test_config(filename)
#service.print_test_config(config)
validate_test_config(config)
#
# Evaluate Python expressions
#
for item in config.get('python', []):
try:
exec(item, _globals)
except Exception:
err = sys.exc_info()[1]
print("ERROR executing '%s'" % item)
print(" Exception: %s" % str(err))
#
# Create test driver, which is put in the global namespace
#
driver = plugins.TestDriverFactory(config['driver'])
if driver is None:
raise IOError("Unexpected test driver '%s'" % config['driver'])
_globals["test_driver"] = driver
#
# Generate suite
#
for suite in config.get('suites', {}):
create_test_suite(suite, config, _globals, options)
示例2: run
# 需要导入模块: from pyutilib.misc import Options [as 别名]
# 或者: from pyutilib.misc.Options import categories [as 别名]
def run(argv, _globals=None):
#
# Set sys.argv to the value specified by the user
#
sys.argv = argv
#
# Create the option parser
#
parser = optparse.OptionParser()
parser.remove_option('-h')
#
parser.add_option('-h','--help',
action='store_true',
dest='help',
default=False,
help='Print command options')
#
parser.add_option('-d','--debug',
action='store_true',
dest='debug',
default=False,
help='Set debugging flag')
#
parser.add_option('-v','--verbose',
action='store_true',
dest='verbose',
default=False,
help='Verbose output')
#
parser.add_option('-q','--quiet',
action='store_true',
dest='quiet',
default=False,
help='Minimal output')
#
parser.add_option('-f','--failfast',
action='store_true',
dest='failfast',
default=False,
help='Stop on first failure')
#
parser.add_option('-c','--catch',
action='store_true',
dest='catch',
default=False,
help='Catch control-C and display results')
#
parser.add_option('-b','--buffer',
action='store_true',
dest='buffer',
default=False,
help='Buffer stdout and stderr durring test runs')
#
parser.add_option('--cat', '--category',
action='append',
dest='categories',
default=[],
help='Define a list of categories that filter the execution of test suites')
#
parser.add_option('--help-suites',
action='store_true',
dest='help_suites',
default=False,
help='Print the test suites that can be executed')
#
parser.add_option('--help-tests',
action='store',
dest='help_tests',
default=None,
help='Print the tests in the specified test suite')
#
parser.add_option('--help-categories',
action='store_true',
dest='help_categories',
default=False,
help='Print the test suite categories that can be specified')
#
# Parse the argument list and print help info if needed
#
_options, args = parser.parse_args(sys.argv)
if _options.help:
parser.print_help()
print("""
Examples:
%s - run all test suites
%s MyTestCase.testSomething - run MyTestCase.testSomething
%s MyTestCase - run all 'test*' test methods
in MyTestCase
""" % (args[0],args[0],args[0]))
return
#
# If no value for _globals is specified, then we use the current context.
#
if _globals is None:
_globals=globals()
#
# Setup and Options object and create test suites from the specified
# configuration files.
#
#.........这里部分代码省略.........