本文整理汇总了Python中pytest.exit函数的典型用法代码示例。如果您正苦于以下问题:Python exit函数的具体用法?Python exit怎么用?Python exit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了exit函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_options
def check_options(config):
"""Process options to manipulate (produce other options) important for pytest-cloud."""
if getattr(config, 'slaveinput', {}).get('slaveid', 'local') == 'local' and config.option.cloud_nodes:
patches.apply_patches()
mem_per_process = config.option.cloud_mem_per_process
if mem_per_process:
mem_per_process = mem_per_process * 1024 * 1024
virtualenv_path = config.option.cloud_virtualenv_path
chdir = config.option.cloud_chdir
python = config.option.cloud_python
node_specs = get_nodes_specs(
config.option.cloud_nodes,
chdir=chdir,
python=python,
virtualenv_path=virtualenv_path,
rsync_max_processes=config.option.cloud_rsync_max_processes,
rsync_bandwidth_limit=config.option.cloud_rsync_bandwidth_limit,
max_processes=config.option.cloud_max_processes,
mem_per_process=mem_per_process,
config=config)
if node_specs:
print('Scheduling with {0} parallel test sessions'.format(len(node_specs)))
if not node_specs:
pytest.exit('None of the given test nodes are able to serve as a test node due to capabilities')
config.option.tx += node_specs
config.option.dist = 'load'
示例2: execute_before_any_test
def execute_before_any_test():
print "Initializing tests"
platform = pytest.config.getoption("--platform")
if not platform:
message = ["\n",
"Error running tests. Please specify a platform with a --platform flag, for example py.test tests --platform=browser",
"List of available platforms:",
"browser: run tests in the browser (with Peerio.AutomationSocket === true)",
"ios: run tests in the simulator",
"android: run tests in the GenyMotion simulator (please launch it before start)",
""]
pytest.exit('\n'.join(message))
return
method = getattr(common.helper, 'platform_' + platform)
if not method:
pytest.exit('platform not found: ' + platform)
return
platform_options = method()
set_platform(platform_options)
if 'appium' in platform_options and platform_options['appium']:
restartAppium()
if 'browserautomation' in platform_options and platform_options['browserautomation']:
restartBrowserAutomation()
if 'chromeriver' in platform_options and platform_options['chromedriver']:
restartChromedriver()
示例3: stop
def stop(self):
"""Stop ManagedSubprocess instance and perform a cleanup
This method makes sure that there are no child processes left after
the object destruction finalizes. In case when a process cannot stop
on it's own, it's forced to using SIGTERM/SIGKILL.
"""
self._process.poll()
if self._process.returncode is not None:
msg_fmt = "`%s` process has already terminated with code `%s`"
pytest.exit(msg_fmt % (self.id, self._process.returncode))
return
log.info("Send SIGINT to `%s` session leader", self.id)
self._process.send_signal(signal.SIGINT)
try:
self._process.wait(self._EXIT_TIMEOUT / 2.0)
except subprocess.TimeoutExpired:
log.info("Send SIGTERM to `%s` session leader", self.id)
self._process.send_signal(signal.SIGTERM)
try:
self._process.wait(self._EXIT_TIMEOUT / 2.0)
except subprocess.TimeoutExpired:
log.info("Send SIGKILL to all `%s` processess", self.id)
os.killpg(os.getpgid(self._process.pid), signal.SIGKILL)
log.info("wait() for `%s` session leader to die", self.id)
self._process.wait()
log.info("`%s` session leader has terminated", self.id)
示例4: pytest_sessionstart
def pytest_sessionstart(session):
from .core import LibJulia, JuliaInfo, Julia, enable_debug
options = JuliaOptions()
for desc in JuliaOptions.supported_options():
cli_option = "--julia-{}".format(desc.cli_argument_name().lstrip("-"))
desc.__set__(options, session.config.getoption(cli_option))
julia_runtime = session.config.getoption("julia_runtime")
global _USING_DEFAULT_SETUP
_USING_DEFAULT_SETUP = not (julia_runtime != "julia" or options.as_args())
if not session.config.getoption("julia"):
return
enable_debug()
global _JULIA_INFO
_JULIA_INFO = info = JuliaInfo.load(julia=julia_runtime)
if not info.is_pycall_built():
print(
"""
PyCall is not installed or built. Run the following code in Python REPL:
>>> import julia
>>> julia.install()
See:
https://pyjulia.readthedocs.io/en/latest/installation.html
""",
file=sys.stderr,
)
pytest.exit("PyCall not built", returncode=1)
if (
options.compiled_modules != "no"
and not info.is_compatible_python()
and info.version_info >= (0, 7)
):
print(
"""
PyJulia does not fully support this combination of Julia and Python.
Try:
* Pass `--julia-compiled-modules=no` option to disable
precompilation cache.
* Use `--julia-runtime` option to specify different Julia
executable.
* Pass `--no-julia` to run tests that do not rely on Julia
runtime.
""",
file=sys.stderr,
)
pytest.exit("incompatible runtimes", returncode=1)
api = LibJulia.from_juliainfo(info)
api.init_julia(options)
示例5: __init__
def __init__(self):
self.logger = logging.getLogger(__name__)
self.docker = docker.from_env()
if len(self.docker.images(name=self.image_name)) == 0:
self._fetch_image()
host_config = self.docker.create_host_config(
binds=self.volumes_bindings,
port_bindings=self.port_bindings
)
try:
# following avoids conflict between different builds
container_name_prefixed = '{}_{}'.format(os.path.basename(os.path.realpath('{}/../..'.format(__file__))),
self.container_name)
self.container_id = self.docker.create_container(self.image_name, name=container_name_prefixed,
ports=self.ports, command=self.command,
environment=self.env_vars,
volumes=self.volumes, host_config=host_config).get('Id')
self.logger.info("docker id is {}".format(self.container_id))
self.logger.info("starting the temporary docker for image {}".format(self.image_name))
self.docker.start(self.container_id)
self.ip_addr = self.docker.inspect_container(self.container_id).get('NetworkSettings', {}).get('IPAddress')
if not self.ip_addr:
self.logger.error("temporary docker {} not started".format(self.container_id))
assert False
self.logger.info("IP addr is {}".format(self.ip_addr))
self.wait_until_available()
except APIError as e:
pytest.exit(
"error during setup of docker container {}, aborting. Details:\n{}".format(container_name_prefixed,
str(e)))
示例6: pytest_cmdline_main
def pytest_cmdline_main(config):
"""
Enforce test environment before loading fixtures and running tests
This helps prevent accidents like creating/dropping the db in a stage/prod
environment when running the test suite
"""
if os.environ.get('CONFIG_ENV') != 'test':
pytest.exit('Please set CONFIG_ENV=test before running test suite')
示例7: exit_if_switch_used_with_xdist
def exit_if_switch_used_with_xdist(session, switch_list):
if hasattr(session.config, 'slaveinput'):
for switch_str in switch_list:
if session.config.getoption(switch_str):
pytest.exit(
'Cannot use {} when running in parallel under pytest-xdist '
'(e.g., -n --dist --tx)'.format(switch_str)
)
示例8: prepare_test
def prepare_test(dirname, testfile):
if not os.path.exists(nserv_datadir + '/' + dirname + '.nzb'):
os.makedirs(nserv_datadir + '/' + dirname)
shutil.copyfile(testdata_dir + '/rarrenamer/' + testfile + '.part01.rar', nserv_datadir + '/' + dirname + '/abc.21')
shutil.copyfile(testdata_dir + '/rarrenamer/' + testfile + '.part02.rar', nserv_datadir + '/' + dirname + '/abc.02')
shutil.copyfile(testdata_dir + '/rarrenamer/' + testfile + '.part03.rar', nserv_datadir + '/' + dirname + '/abc.15')
os.chdir(nserv_datadir + '/' + dirname)
if 0 != subprocess.call([par2_bin, 'c', '-b20', 'parrename.par2', '*']):
pytest.exit('Test file generation failed')
示例9: validate_pytest_config
def validate_pytest_config():
"""
Validate that pytest command line options make sense.
"""
if pytest.config.option.testing_remote_cluster:
local_prefixes = ('localhost', '127.', '0.0.0.0')
if any(pytest.config.option.impalad.startswith(loc) for loc in local_prefixes):
logging.error("--testing_remote_cluster can not be used with a local impalad")
pytest.exit("Invalid pytest config option: --testing_remote_cluster")
示例10: pytest_generate_tests
def pytest_generate_tests(metafunc):
if 'engine' in metafunc.fixturenames:
engines = []
for e in metafunc.config.option.engine.split(','):
if e in ['theano_engine', 'dict_engine']:
engines.append(e)
if not engines:
pytest.exit("Unknown engine.")
metafunc.parametrize("engine", engines, scope="session")
示例11: pytest_configure
def pytest_configure(config):
"Assert that the environment is correctly configured."
global topology_only
if not diagnose_env():
pytest.exit('enviroment has errors, please read the logs')
if config.getoption('--topology-only'):
topology_only = True
示例12: verify_cleanup
def verify_cleanup():
"""Verify that the test has cleaned up resources correctly."""
yield
if len(INSTANCES) >= 2:
count = len(INSTANCES)
for inst in INSTANCES:
inst.stop()
pytest.exit("Detected non stopped instances "
"({}), aborting test run".format(count))
示例13: atomic_data_fname
def atomic_data_fname(tardis_ref_path):
atomic_data_fname = os.path.join(
tardis_ref_path, 'atom_data', 'kurucz_cd23_chianti_H_He.h5')
atom_data_missing_str = ("{0} atomic datafiles "
"does not seem to exist".format(atomic_data_fname))
if not os.path.exists(atomic_data_fname):
pytest.exit(atom_data_missing_str)
return atomic_data_fname
示例14: check_fullfilled
def check_fullfilled(self):
try:
result = self.request_check()
except SproutException as e:
# TODO: ensure we only exit this way on sprout usage
self.destroy_pool()
log.error("sprout pool could not be fulfilled\n%s", str(e))
pytest.exit(1)
log.debug("fulfilled at %f %%", result['progress'])
return result["fulfilled"]
示例15: pytest_configure
def pytest_configure():
# Make sure we are in the correct folder for the test.
dirname = os.path.split(os.getcwd())[1]
if not dirname=='Tests':
pytest.exit("Not running in the Tests folder!")
# Make sure the data is downloaded
from ..Scripts import get_data_files
return