本文整理汇总了Python中pytest.fail函数的典型用法代码示例。如果您正苦于以下问题:Python fail函数的具体用法?Python fail怎么用?Python fail使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fail函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_freeze_bazaar_clone
def test_freeze_bazaar_clone(script, tmpdir):
"""
Test freezing a Bazaar clone.
"""
try:
checkout_path = _create_test_package(script, vcs='bazaar')
except OSError as e:
pytest.fail('Invoking `bzr` failed: %s' % e)
result = script.run(
'bzr', 'checkout', checkout_path, 'bzr-package'
)
result = script.run(
'python', 'setup.py', 'develop',
cwd=script.scratch_path / 'bzr-package',
expect_stderr=True,
)
result = script.pip('freeze', expect_stderr=True)
expected = textwrap.dedent("""\
...-e bzr+file://[email protected]#egg=version_pkg
...""")
_check_output(result.stdout, expected)
result = script.pip(
'freeze', '-f',
'%s/#egg=django-wikiapp' % checkout_path,
expect_stderr=True,
)
expected = textwrap.dedent("""\
-f %(repo)s/#egg=django-wikiapp
...-e bzr+file://[email protected]#egg=version_pkg
...""" % {'repo': checkout_path})
_check_output(result.stdout, expected)
开发者ID:alquerci,项目名称:pip,代码行数:34,代码来源:test_freeze.py
示例2: fnmatch_lines
def fnmatch_lines(self, lines2):
"""Search the text for matching lines.
The argument is a list of lines which have to match and can
use glob wildcards. If they do not match an pytest.fail() is
called. The matches and non-matches are also printed on
stdout.
"""
def show(arg1, arg2):
py.builtin.print_(arg1, arg2, file=sys.stderr)
lines2 = self._getlines(lines2)
lines1 = self.lines[:]
nextline = None
extralines = []
__tracebackhide__ = True
for line in lines2:
nomatchprinted = False
while lines1:
nextline = lines1.pop(0)
if line == nextline:
show("exact match:", repr(line))
break
elif fnmatch(nextline, line):
show("fnmatch:", repr(line))
show(" with:", repr(nextline))
break
else:
if not nomatchprinted:
show("nomatch:", repr(line))
nomatchprinted = True
show(" and:", repr(nextline))
extralines.append(nextline)
else:
pytest.fail("remains unmatched: %r, see stderr" % (line,))
开发者ID:JanBednarik,项目名称:pytest,代码行数:35,代码来源:pytester.py
示例3: test_implement_tokenize_words
def test_implement_tokenize_words(self):
"""
Ensure functionality is implemented.
| *Test Suite ID* : L
|
| *Test Case Number* : 04
|
| *Description* : Ensure that the word level clean functionality
| is implemented in the class.
| Tests :func:`LeipzigPreprocessor._tokenize_words`
|
| *Preconditions* : LeipzigPreprocessor class instance exists.
|
| *Test Parameters* : sentence passed to function.
|
| *Test Data* : sentence=''
|
| *Expected Result* : NotImplementedError exception is not raised.
|
| *Actual Result* : NotImplementedError exception is not raised.
|
| **Status : Pass**
|
"""
testing_object = self.__class__.testing_obj
try:
testing_object._tokenize_words(sentence='')
except NotImplementedError:
pytest.fail('Not Implemented _tokenize_words function')
开发者ID:KshitijKarthick,项目名称:tvecs,代码行数:31,代码来源:test_leipzig_preprocessor.py
示例4: destroy_marathon_app
def destroy_marathon_app(self, app_name, timeout=300):
"""Remove a marathon app
Abort the test if the removal was unsuccesful.
Args:
app_name: name of the applicatoin to remove
timeout: seconds to wait for destruction before failing test
"""
@retrying.retry(wait_fixed=1000, stop_max_delay=timeout*1000,
retry_on_result=lambda ret: not ret,
retry_on_exception=lambda x: False)
def _destroy_complete(deployment_id):
r = self.get('/marathon/v2/deployments', headers=self._marathon_req_headers())
assert r.ok
for deployment in r.json():
if deployment_id == deployment.get('id'):
logging.info('Waiting for application to be destroyed')
return False
logging.info('Application destroyed')
return True
r = self.delete('/marathon/v2/apps' + app_name, headers=self._marathon_req_headers())
assert r.ok
try:
_destroy_complete(r.json()['deploymentId'])
except retrying.RetryError:
pytest.fail("Application destroy failed - operation was not "
"completed in {} seconds.".format(timeout))
开发者ID:luoch,项目名称:dcos,代码行数:31,代码来源:conftest.py
示例5: verify_source
def verify_source(source_files, gz_path):
"""Ensure the std python dist files and source_files are in the .tar.gz."""
f_name = glob.glob(os.path.join(gz_path, "*.tar.gz"))[0]
with tarfile.open(f_name, "r:gz") as tar_file:
tar_files = tar_file.getnames()
pkg_full_name = os.path.basename(
os.path.dirname(gz_path)
).split(".tar.gz")[0]
egg_name = "{}.egg-info".format(pkg_full_name.rsplit("-")[0]) # fragile..
source_files.extend([
"PKG-INFO",
egg_name,
os.path.join(egg_name, "dependency_links.txt"),
os.path.join(egg_name, "PKG-INFO"),
os.path.join(egg_name, "SOURCES.txt"),
os.path.join(egg_name, "top_level.txt"),
"setup.cfg",
"setup.py",
])
assert len(tar_files) == len(source_files) + 1 # +1 for the base dir
base_dir_skipped = False
for tar_file in tar_files:
assert tar_file.startswith(pkg_full_name)
if os.path.sep in tar_file:
tar_file = tar_file[tar_file.index(os.path.sep) + 1:]
assert tar_file in source_files
elif not base_dir_skipped:
base_dir_skipped = True
else:
pytest.fail("{} not expected in source dist!".format(tar_file))
开发者ID:Zearin,项目名称:pypackage,代码行数:32,代码来源:test_builds.py
示例6: _test_executables
def _test_executables(self, name, args, runtime, run_from_path):
"""
Run created executable to make sure it works.
Multipackage-tests generate more than one exe-file and all of
them have to be run.
:param args: CLI options to pass to the created executable.
:param runtime: Time in miliseconds how long to keep the executable running.
:return: Exit code of the executable.
"""
__tracebackhide__ = True
# TODO implement runtime - kill the app (Ctrl+C) when time times out
exes = self._find_executables(name)
# Empty list means that PyInstaller probably failed to create any executable.
assert exes != [], 'No executable file was found.'
for exe in exes:
# Try to find .toc log file. .toc log file has the same basename as exe file.
toc_log = os.path.join(_LOGS_DIR, os.path.basename(exe) + '.toc')
if os.path.exists(toc_log):
if not self._examine_executable(exe, toc_log):
pytest.fail('Matching .toc of %s failed.' % exe)
retcode = self._run_executable(exe, args, run_from_path, runtime)
if retcode != 0:
pytest.fail('Running exe %s failed with return-code %s.' %
(exe, retcode))
开发者ID:jayfk,项目名称:pyinstaller,代码行数:27,代码来源:conftest.py
示例7: test_insert
def test_insert(empty_warehouse):
"""
Inserts a fact with MAX_ITERATIONS ^ 2 rows.
"""
enable_logging()
Warehouse.use(empty_warehouse)
Store.build()
stores = _get_instances('store')
Store.insert(*stores)
Product.build()
products = _get_instances('product')
Product.insert(*products)
Sales.build()
sales = _get_instances('sales')
start_time = datetime.datetime.now()
print 'Starting bulk insert of fact at ', start_time
try:
Sales.insert(*sales)
except OperationalError:
pytest.fail('The connection broke.')
end_time = datetime.datetime.now()
print 'Ending bulk insert of fact at ', end_time
delta = end_time - start_time
print 'Time taken = ', delta
开发者ID:gregorynicholas,项目名称:pylytics,代码行数:32,代码来源:test_performance.py
示例8: test_blocking_read
def test_blocking_read(conn, monkeypatch):
path = '/foo/wurfl'
chunks = [120] * 10
delay = 10
while True:
monkeypatch.setattr(MockRequestHandler, 'do_GET',
get_chunked_GET_handler(path, chunks, delay))
conn.send_request('GET', path)
resp = conn.read_response()
assert resp.status == 200
interrupted = 0
parts = []
while True:
crt = conn.co_read(100)
try:
while True:
io_req = next(crt)
interrupted += 1
assert io_req.poll(5)
except StopIteration as exc:
buf = exc.value
if not buf:
break
parts.append(buf)
assert not conn.response_pending()
assert _join(parts) == b''.join(DUMMY_DATA[:x] for x in chunks)
if interrupted >= 8:
break
elif delay > 5000:
pytest.fail('no blocking read even with %f sec sleep' % delay)
delay *= 2
开发者ID:python-dugong,项目名称:python-dugong,代码行数:35,代码来源:test_dugong.py
示例9: test_action_tag
def test_action_tag(request, assign_policy_for_testing, vm, vm_off, vm_crud_refresh):
""" Tests action tag
Metadata:
test_flag: actions, provision
"""
if any(tag.category.display_name == "Service Level" and tag.display_name == "Gold"
for tag in vm.crud.get_tags()):
vm.crud.remove_tag(("Service Level", "Gold"))
tag_assign_action = actions.Action(
fauxfactory.gen_alphanumeric(),
action_type="Tag",
action_values={"tag": ("My Company Tags", "Service Level", "Gold")}
)
assign_policy_for_testing.assign_actions_to_event("VM Power On", [tag_assign_action])
@request.addfinalizer
def finalize():
assign_policy_for_testing.assign_events()
tag_assign_action.delete()
vm.start_vm()
vm_crud_refresh()
try:
wait_for(
lambda: any(tag.category.display_name == "Service Level" and tag.display_name == "Gold"
for tag in vm.crud.get_tags()),
num_sec=600,
message="tag presence check"
)
except TimedOutError:
pytest.fail("Tags were not assigned!")
开发者ID:ManageIQ,项目名称:integration_tests,代码行数:33,代码来源:test_actions.py
示例10: tst_lock_rm
def tst_lock_rm(self):
# Extract tar
tempdir = os.path.join(self.mnt_dir, 'lock_dir')
filename = os.path.join(tempdir, 'myfile')
os.mkdir(tempdir)
with open(filename, 'w') as fh:
fh.write('Hello, world')
# copy
try:
s3ql.lock.main([tempdir])
except:
sys.excepthook(*sys.exc_info())
pytest.fail("s3qllock raised exception")
# Try to delete
assert_raises(PermissionError, os.unlink, filename)
# Try to write
with pytest.raises(PermissionError):
open(filename, 'w+').write('Hello')
# delete properly
try:
s3ql.remove.main([tempdir])
except:
sys.excepthook(*sys.exc_info())
pytest.fail("s3qlrm raised exception")
assert 'lock_dir' not in llfuse.listdir(self.mnt_dir)
开发者ID:NickChen0113,项目名称:s3ql,代码行数:31,代码来源:t5_lock_rm.py
示例11: _test_run
def _test_run(self, protocol):
fh = open('/tmp/hb.txt', 'w')
list_for_find = ['wrtest.com', 'some', 'nf', 'aaa.wrtest.com']
for obj in list_for_find:
fh.write("{0}\n".format(obj))
fh.close()
queue = HostsBruteJob()
generator = FileGenerator('/tmp/hb.txt')
queue.set_generator(generator)
result = []
thrd = HostsBruteThread(
queue=queue,
protocol=protocol,
host='wrtest.com',
template='@',
mask_symbol='@',
false_phrase='403 Forbidden',
retest_codes='',
delay=0,
ignore_words_re='',
counter=CounterMock(),
result=result
)
thrd.setDaemon(True)
thrd.start()
start_time = int(time.time())
while not thrd.done:
if int(time.time()) - start_time > self.threads_max_work_time:
pytest.fail("Thread work {0} secs".format(int(time.time()) - start_time))
time.sleep(1)
assert result == ['wrtest.com', 'aaa.wrtest.com']
开发者ID:hack4sec,项目名称:ws-cli,代码行数:35,代码来源:test_HostsBruterThread.py
示例12: test_mrsid_online_4
def test_mrsid_online_4():
if gdaltest.jp2mrsid_drv is None:
pytest.skip()
if not gdaltest.download_file('http://www.openjpeg.org/samples/Bretagne2.j2k', 'Bretagne2.j2k'):
pytest.skip()
if not gdaltest.download_file('http://www.openjpeg.org/samples/Bretagne2.bmp', 'Bretagne2.bmp'):
pytest.skip()
# Checksum = 53186 on my PC
tst = gdaltest.GDALTest('JP2MrSID', 'tmp/cache/Bretagne2.j2k', 1, None, filename_absolute=1)
tst.testOpen()
ds = gdal.Open('tmp/cache/Bretagne2.j2k')
ds_ref = gdal.Open('tmp/cache/Bretagne2.bmp')
maxdiff = gdaltest.compare_ds(ds, ds_ref, width=256, height=256)
ds = None
ds_ref = None
# Difference between the image before and after compression
if maxdiff > 1:
print(ds.GetRasterBand(1).Checksum())
print(ds_ref.GetRasterBand(1).Checksum())
pytest.fail('Image too different from reference')
开发者ID:AsgerPetersen,项目名称:gdal,代码行数:27,代码来源:mrsid.py
示例13: test_mrsid_2
def test_mrsid_2():
if gdaltest.mrsid_drv is None:
pytest.skip()
ds = gdal.Open('data/mercator.sid')
try:
data = ds.ReadRaster(0, 0, 515, 515, buf_xsize=10, buf_ysize=10)
except:
pytest.fail('Small overview read failed: ' + gdal.GetLastErrorMsg())
ds = None
is_bytes = False
if (isinstance(data, bytes) and not isinstance(data, str)):
is_bytes = True
# check that we got roughly the right values by checking mean.
if is_bytes is True:
total = sum(data)
else:
total = sum([ord(c) for c in data])
mean = float(total) / len(data)
assert mean >= 95 and mean <= 105, 'image mean out of range.'
开发者ID:AsgerPetersen,项目名称:gdal,代码行数:27,代码来源:mrsid.py
示例14: test_vm_discovery
def test_vm_discovery(request, setup_provider, provider, vm_crud):
""" Tests whether cfme will discover a vm change (add/delete) without being manually refreshed.
Prerequisities:
* Desired provider set up
Steps:
* Create a virtual machine on the provider.
* Wait for the VM to appear
* Delete the VM from the provider (not using CFME)
* Wait for the VM to become Archived.
Metadata:
test_flag: discovery
"""
@request.addfinalizer
def _cleanup():
vm_crud.delete_from_provider()
if_scvmm_refresh_provider(provider)
vm_crud.create_on_provider(allow_skip="default")
if_scvmm_refresh_provider(provider)
try:
vm_crud.wait_to_appear(timeout=600, load_details=False)
except TimedOutError:
pytest.fail("VM was not found in CFME")
vm_crud.delete_from_provider()
if_scvmm_refresh_provider(provider)
wait_for_vm_state_changes(vm_crud)
开发者ID:richardfontana,项目名称:cfme_tests,代码行数:31,代码来源:test_discovery.py
示例15: test_abort_co_read
def test_abort_co_read(conn, monkeypatch):
# We need to delay the write to ensure that we encounter a blocking read
path = '/foo/wurfl'
chunks = [300, 317, 283]
delay = 10
while True:
monkeypatch.setattr(MockRequestHandler, 'do_GET',
get_chunked_GET_handler(path, chunks, delay))
conn.send_request('GET', path)
resp = conn.read_response()
assert resp.status == 200
cofun = conn.co_read(450)
try:
next(cofun)
except StopIteration:
# Not good, need to wait longer
pass
else:
break
finally:
conn.disconnect()
if delay > 5000:
pytest.fail('no blocking read even with %f sec sleep' % delay)
delay *= 2
assert_raises(dugong.ConnectionClosed, next, cofun)
开发者ID:python-dugong,项目名称:python-dugong,代码行数:27,代码来源:test_dugong.py
示例16: after_test
def after_test(self, did_fail): # pylint: disable=arguments-differ
"""Handle unexpected/skip logging and clean up after each test.
Args:
did_fail: Set if the main test failed already, then logged errors
are ignored.
"""
__tracebackhide__ = True
bad_msgs = [msg for msg in self._data
if self._is_error_logline(msg) and not msg.expected]
if did_fail:
super().after_test()
return
try:
if bad_msgs:
text = 'Logged unexpected errors:\n\n' + '\n'.join(
str(e) for e in bad_msgs)
# We'd like to use pytrace=False here but don't as a WORKAROUND
# for https://github.com/pytest-dev/pytest/issues/1316
pytest.fail(text)
else:
self._maybe_skip()
finally:
super().after_test()
开发者ID:AdaJass,项目名称:qutebrowser,代码行数:26,代码来源:quteprocess.py
示例17: test_build_file_metadata_from_tree
def test_build_file_metadata_from_tree(self, metadata_fixtures):
try:
metadata = GitHubFileTreeMetadata(metadata_fixtures['file_metadata_tree_endpoint'])
except Exception as exc:
pytest.fail(str(exc))
assert metadata.name == 'README.md'
assert metadata.path == '/README.md'
assert metadata.modified is None
assert metadata.content_type is None
assert metadata.size == 38
assert metadata.size_as_int == 38
assert type(metadata.size_as_int) == int
assert metadata.etag == '/README.md::d863d70539aa9fcb6b44b057221706f2ab18e341'
assert metadata.extra == {
'fileSha': 'd863d70539aa9fcb6b44b057221706f2ab18e341',
'webView': None,
'hashes': {
'git': 'd863d70539aa9fcb6b44b057221706f2ab18e341',
},
}
assert metadata.provider == 'github'
assert metadata.commit is None
assert metadata.ref is None
assert metadata.web_view is None
开发者ID:CenterForOpenScience,项目名称:waterbutler,代码行数:26,代码来源:test_metadata.py
示例18: test_warning_no
def test_warning_no():
"""No shadow warning is raised"""
with rasterio.open('tests/data/RGB.byte.tif') as src:
try:
rm, gm, bm = src.read_masks()
except NodataShadowWarning:
pytest.fail("Unexpected NodataShadowWarning raised")
开发者ID:DanLipsitt,项目名称:rasterio,代码行数:7,代码来源:test_band_masks.py
示例19: test_build_file_metadata_from_contents
def test_build_file_metadata_from_contents(self, metadata_fixtures):
try:
metadata = GitHubFileContentMetadata(metadata_fixtures['file_metadata_content_endpoint'])
except Exception as exc:
pytest.fail(str(exc))
assert metadata.name == 'epsilon'
assert metadata.path == '/epsilon'
assert metadata.modified is None
assert metadata.content_type is None
assert metadata.size == 15
assert metadata.size_as_int == 15
assert type(metadata.size_as_int) == int
assert metadata.etag == '/epsilon::bd4fb614678f544acb22bac6861a21108f1e5d10'
assert metadata.extra == {
'fileSha': 'bd4fb614678f544acb22bac6861a21108f1e5d10',
'webView': None,
'hashes': {
'git': 'bd4fb614678f544acb22bac6861a21108f1e5d10',
},
}
assert metadata.provider == 'github'
assert metadata.commit is None
assert metadata.ref is None
assert metadata.web_view is None
开发者ID:CenterForOpenScience,项目名称:waterbutler,代码行数:26,代码来源:test_metadata.py
示例20: tst_ctrl_flush
def tst_ctrl_flush(self):
try:
s3ql.ctrl.main(['flushcache', self.mnt_dir])
except:
sys.excepthook(*sys.exc_info())
pytest.fail("s3qlctrl raised exception")
开发者ID:NickChen0113,项目名称:s3ql,代码行数:7,代码来源:t5_ctrl.py
注:本文中的pytest.fail函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论