本文整理汇总了Python中pytest.main函数的典型用法代码示例。如果您正苦于以下问题:Python main函数的具体用法?Python main怎么用?Python main使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了main函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
def run(self, params, args):
(exitonfail, pretty) = self.fillParams([
('exitonfail', False),
('pretty', True)
])
exitonfail = self.str2bool(exitonfail)
pretty = self.str2bool(pretty)
current_dir = os.getcwd()
os.chdir('/opt/stack/lib/python3.7/site-packages/stack/commands/report/system')
tests = glob('tests/*')
# make it real ugly.
if exitonfail and not pretty:
_return_code = main(['--verbose', '--exitfirst', *args, *tests])
# exit with first failure
elif exitonfail:
_return_code = main(['--verbose', '--capture=no', '--exitfirst', *args, *tests])
# show tracebacks of failures but don't fail.
elif not pretty:
_return_code = main(['--verbose', '--capture=no', *args, *tests])
# pretty and no tracebacks
else:
_return_code = main(['--verbose', '--capture=no', '--tb=no', *args, *tests])
os.chdir(current_dir)
# If any of the tests failed, throw an error
if _return_code > 0:
raise CommandError(self, "One or more tests failed")
示例2: test
def test(arguments=''):
"""Run ODL tests given by arguments."""
import pytest
this_dir = os.path.dirname(__file__)
odl_root = os.path.abspath(os.path.join(this_dir, os.pardir, os.pardir))
base_args = '-x {odl_root}/odl {odl_root}/test '.format(odl_root=odl_root)
pytest.main(base_args + arguments)
示例3: test_pytest
def test_pytest():
try:
import pytest
import os
pytest.main('-xvs %s' % os.path.dirname(__file__))
except ImportError:
print 'error importing pytest'
示例4: run
def run(self):
import pytest
if self.noweb:
exit_code = pytest.main(['-m', 'not web'])
else:
exit_code = pytest.main([])
sys.exit(exit_code)
示例5: main
def main():
logging.basicConfig(level=logging.DEBUG)
# cleanup any existing data
netnode.Netnode(TEST_NAMESPACE).kill()
pytest.main(['--capture=sys', os.path.dirname(__file__)])
示例6: run_tests
def run_tests(args):
"""Run tests."""
args = args # args is unused
path = os.path.abspath(os.path.dirname(__file__))
sys.argv[1] = path
pytest.main()
示例7: main
def main():
if len(sys.argv) > 1:
wd = sys.argv[1]
else:
wd = "."
student_dirs = filter(os.path.isdir, os.listdir(wd))
students = []
for sdir in student_dirs:
os.path.join(wd, sdir)
class Student:
name = sdir
dirname = os.path.join(wd, sdir)
students.append(Student)
for s in students:
for fname in os.listdir(s.dirname):
if fname.startswith("test_"):
s.code = open(os.path.join(s.dirname, fname)).read()
s.code = s.code.replace("def test_", "def test_" + s.name + "_")
code = "\n".join(s.code for s in students)
pooled_test_paths = []
for s in students:
path = os.path.join(s.dirname, "tests_pooled.py")
fw = open(path, "w")
fw.write(code)
fw.close()
print "Written", path
pooled_test_paths.append(path)
init_path = os.path.join(s.dirname, "__init__.py")
if not os.path.isfile(init_path):
open(init_path, "w").close()
for path in pooled_test_paths:
pytest.main(["--color=no", path])
示例8: run_tests
def run_tests(self):
import pytest
error_code = pytest.main(['-k', 'parse/test/test_settings.py'])
if error_code:
sys.exit(errcode)
errcode = pytest.main(self.test_args)
sys.exit(errcode)
示例9: do_list
def do_list(args, unknown_args):
"""Print a lists of tests than what pytest offers."""
# Run test collection and get the tree out.
old_output = sys.stdout
try:
sys.stdout = output = StringIO()
pytest.main(['--collect-only'])
finally:
sys.stdout = old_output
# put the output in a more readable tree format.
lines = output.getvalue().split('\n')
output_lines = []
for line in lines:
match = re.match(r"(\s*)<([^ ]*) '([^']*)'", line)
if not match:
continue
indent, nodetype, name = match.groups()
# only print top-level for short list
if args.list:
if not indent:
output_lines.append(
os.path.basename(name).replace('.py', ''))
else:
print(indent + name)
if args.list:
colify(output_lines)
示例10: merge_config
def merge_config(args):
collect_config = CollectConfig()
with silence():
pytest.main(['--collect-only'], plugins=[collect_config])
if not collect_config.path:
return
config = ConfigParser()
config.read(collect_config.path)
if not config.has_section('pytest-watch'):
return
for cli_name in args:
if not cli_name.startswith(CLI_OPTION_PREFIX):
continue
config_name = cli_name[len(CLI_OPTION_PREFIX):]
# Let CLI options take precedence
if args[cli_name]:
continue
# Find config option
if not config.has_option('pytest-watch', config_name):
continue
# Merge config option using the expected type
if isinstance(args[cli_name], bool):
args[cli_name] = config.getboolean('pytest-watch', config_name)
else:
args[cli_name] = config.get('pytest-watch', config_name)
示例11: test
def test():
r"""
Run all the doctests available.
"""
import pytest
path = os.path.split(__file__)[0]
pytest.main(args=[path, '--doctest-modules', '-r s'])
示例12: main
def main(args):
print("Running tests, args:", args)
if args and args != ['-v']:
return pytest.main(['--capture=sys'] + args)
engine = tenjin.Engine(cache=False)
major_version = sys.version_info[0]
minor_version = sys.version_info[1]
# Note: This naming is duplicated in .travis.yml
cov_rc_file_name = jp(_here, '.coverage_rc_' + str(os.environ.get('TRAVIS_PYTHON_VERSION', str(major_version) + '.' + str(minor_version))))
with open(cov_rc_file_name, 'w') as cov_rc_file:
cov_rc_file.write(engine.render(jp(_here, "coverage_rc.tenjin"), dict(
major_version=major_version, minor_version=minor_version, type_check_supported=type_check.vcheck())))
rc = pytest.main(['--capture=sys', '--cov=' + _here + '/..', '--cov-report=term-missing', '--cov-config=' + cov_rc_file_name] + (args if args == ['-v'] else []))
print()
try:
del os.environ['PYTHONPATH']
except KeyError:
pass
for env_name in 'prod', 'preprod', 'devlocal', 'devs', 'devi':
demo_out = jp(_here, env_name + '.demo_out')
print("Validating demo for env {env} - output in {out}".format(env=env_name, out=demo_out))
osenv = {'PYTHONPATH': ':'.join(sys.path)}
with open(demo_out, 'w') as outf:
rc |= subprocess.check_call((sys.executable, _here + '/../demo/demo.py', '--env', env_name), env=osenv, stdout=outf)
print()
return rc
示例13: test
def test(coverage=False):
args = []
if coverage:
args.append("--cov=.")
pytest.main(args)
示例14: main
def main(argv):
if '--help' in argv:
print("Usage: ./runtests.py <testfiles>")
return
mydir = os.path.dirname(os.path.abspath(__file__))
verbosity_args = []
if 'PYGI_TEST_VERBOSE' in os.environ:
verbosity_args += ['--capture=no']
if 'TEST_NAMES' in os.environ:
names = os.environ['TEST_NAMES'].split()
elif 'TEST_FILES' in os.environ:
names = []
for filename in os.environ['TEST_FILES'].split():
names.append(filename[:-3])
elif len(argv) > 1:
names = []
for filename in argv[1:]:
names.append(filename.replace('.py', ''))
else:
return pytest.main([mydir] + verbosity_args)
def unittest_to_pytest_name(name):
parts = name.split(".")
parts[0] = os.path.join(mydir, parts[0] + ".py")
return "::".join(parts)
return pytest.main([unittest_to_pytest_name(n) for n in names] + verbosity_args)
示例15: main
def main():
import os
import sys
from ptvsd.visualstudio_py_debugger import DONT_DEBUG, DEBUG_ENTRYPOINTS, get_code
from ptvsd.attach_server import DEFAULT_PORT, enable_attach, wait_for_attach
sys.path[0] = os.getcwd()
os.chdir(sys.argv[1])
secret = sys.argv[2]
port = int(sys.argv[3])
testFx = sys.argv[4]
args = sys.argv[5:]
DONT_DEBUG.append(os.path.normcase(__file__))
DEBUG_ENTRYPOINTS.add(get_code(main))
enable_attach(secret, ('127.0.0.1', port), redirect_output = False)
sys.stdout.flush()
print('READY')
sys.stdout.flush()
wait_for_attach()
try:
if testFx == 'pytest':
import pytest
pytest.main(args)
else:
import nose
nose.run(argv=args)
sys.exit()
finally:
pass