本文整理匯總了Python中pytest.main方法的典型用法代碼示例。如果您正苦於以下問題:Python pytest.main方法的具體用法?Python pytest.main怎麽用?Python pytest.main使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pytest
的用法示例。
在下文中一共展示了pytest.main方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test
# 需要導入模塊: import pytest [as 別名]
# 或者: from pytest import main [as 別名]
def test(extra_args=None):
try:
import pytest
except ImportError:
raise ImportError("Need pytest>=3.0 to run tests")
try:
import hypothesis # noqa
except ImportError:
raise ImportError("Need hypothesis>=3.58 to run tests")
cmd = ['--skip-slow', '--skip-network', '--skip-db']
if extra_args:
if not isinstance(extra_args, list):
extra_args = [extra_args]
cmd = extra_args
cmd += [PKG]
print("running: pytest {}".format(' '.join(cmd)))
sys.exit(pytest.main(cmd))
示例2: generate
# 需要導入模塊: import pytest [as 別名]
# 或者: from pytest import main [as 別名]
def generate(proto_path, protos):
from grpc_tools import protoc
well_known_path = os.path.join(os.path.dirname(protoc.__file__), '_proto')
proto_out = os.path.join(os.getcwd(), 'protos')
proto_path.append(well_known_path)
proto_path_args = []
for protop in proto_path:
proto_path_args += ['--proto_path', protop]
cmd = [
'grpc_tools.protoc',
*proto_path_args,
'--python_out', proto_out,
'--grpc_python_out', proto_out,
*protos
]
return protoc.main(cmd)
示例3: run
# 需要導入模塊: import pytest [as 別名]
# 或者: from pytest import main [as 別名]
def run(self):
import pytest
import _pytest.main
# Customize messages for pytest exit codes...
msg = {_pytest.main.EXIT_OK: 'OK',
_pytest.main.EXIT_TESTSFAILED: 'Tests failed',
_pytest.main.EXIT_INTERRUPTED: 'Interrupted',
_pytest.main.EXIT_INTERNALERROR: 'Internal error',
_pytest.main.EXIT_USAGEERROR: 'Usage error',
_pytest.main.EXIT_NOTESTSCOLLECTED: 'No tests collected'}
bldobj = self.distribution.get_command_obj('build')
bldobj.run()
exitcode = pytest.main(self.pytest_opts)
print(msg[exitcode])
sys.exit(exitcode)
示例4: pytest_addoption
# 需要導入模塊: import pytest [as 別名]
# 或者: from pytest import main [as 別名]
def pytest_addoption(parser):
parser.addoption(
"--lsof",
action="store_true",
dest="lsof",
default=False,
help="run FD checks if lsof is available",
)
parser.addoption(
"--runpytest",
default="inprocess",
dest="runpytest",
choices=("inprocess", "subprocess"),
help=(
"run pytest sub runs in tests using an 'inprocess' "
"or 'subprocess' (python -m main) method"
),
)
parser.addini(
"pytester_example_dir", help="directory to take the pytester example files from"
)
示例5: inline_runsource
# 需要導入模塊: import pytest [as 別名]
# 或者: from pytest import main [as 別名]
def inline_runsource(self, source, *cmdlineargs):
"""Run a test module in process using ``pytest.main()``.
This run writes "source" into a temporary file and runs
``pytest.main()`` on it, returning a :py:class:`HookRecorder` instance
for the result.
:param source: the source code of the test module
:param cmdlineargs: any extra command line arguments to use
:return: :py:class:`HookRecorder` instance of the result
"""
p = self.makepyfile(source)
values = list(cmdlineargs) + [p]
return self.inline_run(*values)
示例6: run
# 需要導入模塊: import pytest [as 別名]
# 或者: from pytest import main [as 別名]
def run(self, paths):
"""Run pytest test suite."""
cmd = paths + self.pytest_args
print(cmd)
try:
with ShortOutput(self.cmd_root) as so:
errno = pytest.main(cmd)
output_lines = ''.join(so.output).lower()
if 'FAIL Required test coverage'.lower() in output_lines:
self.coverage_fail = True
if errno != 0:
print("pytest failed, code {errno}".format(errno=errno))
except CoverageError as e:
print("Test coverage failure: " + str(e))
self.coverage_fail = True
covered_lines = self.parse_coverage()
pytest_report = self.parse_pytest_report()
results = {'coverage': covered_lines}
if pytest_report is not None:
results['pytest'] = pytest_report
return results
示例7: run_tests_coverage
# 需要導入模塊: import pytest [as 別名]
# 或者: from pytest import main [as 別名]
def run_tests_coverage():
if __name__ == "__main__":
pytest.main(PYTEST_ARGS)
示例8: test
# 需要導入模塊: import pytest [as 別名]
# 或者: from pytest import main [as 別名]
def test():
"""Run the tests."""
import pytest
exit_code = pytest.main([TEST_PATH, '-x', '--verbose'])
return exit_code
示例9: run_tests
# 需要導入模塊: import pytest [as 別名]
# 或者: from pytest import main [as 別名]
def run_tests(self):
import pytest
errno = pytest.main(self.pytest_args)
sys.exit(errno)
示例10: run_tests
# 需要導入模塊: import pytest [as 別名]
# 或者: from pytest import main [as 別名]
def run_tests(self):
# import here, cause outside the eggs aren't loaded
import pytest
err_no = pytest.main(self.pytest_args)
sys.exit(err_no)
示例11: run_tests
# 需要導入模塊: import pytest [as 別名]
# 或者: from pytest import main [as 別名]
def run_tests(self):
import shlex
import pytest
errno = pytest.main(shlex.split(self.pytest_args))
sys.exit(errno)
示例12: run_tests
# 需要導入模塊: import pytest [as 別名]
# 或者: from pytest import main [as 別名]
def run_tests(self):
import pytest
errno = pytest.main(self.test_args)
sys.exit(errno)
示例13: run
# 需要導入模塊: import pytest [as 別名]
# 或者: from pytest import main [as 別名]
def run(self):
"""Run the flake8 linter."""
self.distribution.fetch_build_eggs(test_requires)
self.distribution.packages.append('tests')
from flake8.main import Flake8Command
flake8cmd = Flake8Command(self.distribution)
flake8cmd.options_dict = {}
flake8cmd.run()
示例14: run_tests
# 需要導入模塊: import pytest [as 別名]
# 或者: from pytest import main [as 別名]
def run_tests(self):
"""Run pytest."""
self.distribution.fetch_build_eggs(test_requires)
self.distribution.packages.append('tests')
import pytest
sys.exit(pytest.main(self.pytest_args))
示例15: run
# 需要導入模塊: import pytest [as 別名]
# 或者: from pytest import main [as 別名]
def run():
runs = 40
fails = 0
for x in range(runs):
itr = x + 1
print('running {}'.format(itr))
# tst = 'test_greater_eq_predicate.py::testPredicateGreaterEqMultiIssuers'
# result = pytest.main('-x --tb=long -n 7 {}'.format(tst))
result = pytest.main('-x')
failed = bool(result)
fails += int(failed)
print("{} runs, {} failures".format(runs, fails))