本文整理汇总了Python中pytest.fail方法的典型用法代码示例。如果您正苦于以下问题:Python pytest.fail方法的具体用法?Python pytest.fail怎么用?Python pytest.fail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pytest
的用法示例。
在下文中一共展示了pytest.fail方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_dash_in_project_slug
# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import fail [as 别名]
def test_dash_in_project_slug(cookies):
ctx = {'project_slug': "my-package"}
project = cookies.bake(extra_context=ctx)
assert project.exit_code == 0
with open(os.path.join(str(project.project), 'setup.py')) as f:
setup = f.read()
print(setup)
cwd = os.getcwd()
os.chdir(str(project.project))
try:
sh.python(['setup.py', 'install'])
sh.python(['setup.py', 'build_sphinx'])
except sh.ErrorReturnCode as e:
pytest.fail(e)
finally:
os.chdir(cwd)
示例2: test_vectors
# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import fail [as 别名]
def test_vectors():
with open("vectors.json", "r") as f:
vectors = json.load(f)
for description, mnemonics, secret in vectors:
if secret:
assert bytes.fromhex(secret) == shamir.combine_mnemonics(
mnemonics, b"TREZOR"
), 'Incorrect secret for test vector "{}".'.format(description)
else:
with pytest.raises(MnemonicError):
shamir.combine_mnemonics(mnemonics)
pytest.fail(
'Failed to raise exception for test vector "{}".'.format(
description
)
)
示例3: test_double_quotes_in_name_and_description
# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import fail [as 别名]
def test_double_quotes_in_name_and_description(cookies):
ctx = {'project_short_description': '"double quotes"',
'full_name': '"name"name'}
project = cookies.bake(extra_context=ctx)
assert project.exit_code == 0
with open(os.path.join(str(project.project), 'setup.py')) as f:
setup = f.read()
print(setup)
cwd = os.getcwd()
os.chdir(str(project.project))
try:
sh.python(['setup.py', 'install'])
except sh.ErrorReturnCode as e:
pytest.fail(e)
finally:
os.chdir(cwd)
示例4: test_single_quotes_in_name_and_description
# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import fail [as 别名]
def test_single_quotes_in_name_and_description(cookies):
ctx = {'project_short_description': "'single quotes'",
'full_name': "Mr. O'Keeffe"}
project = cookies.bake(extra_context=ctx)
assert project.exit_code == 0
with open(os.path.join(str(project.project), 'setup.py')) as f:
setup = f.read()
print(setup)
cwd = os.getcwd()
os.chdir(str(project.project))
try:
sh.python(['setup.py', 'install'])
except sh.ErrorReturnCode as e:
pytest.fail(e)
finally:
os.chdir(cwd)
示例5: test_space_in_project_slug
# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import fail [as 别名]
def test_space_in_project_slug(cookies):
ctx = {'project_slug': "my package"}
project = cookies.bake(extra_context=ctx)
assert project.exit_code == 0
with open(os.path.join(str(project.project), 'setup.py')) as f:
setup = f.read()
print(setup)
cwd = os.getcwd()
os.chdir(str(project.project))
try:
sh.python(['setup.py', 'install'])
sh.python(['setup.py', 'build_sphinx'])
except sh.ErrorReturnCode as e:
pytest.fail(e)
finally:
os.chdir(cwd)
示例6: test_install
# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import fail [as 别名]
def test_install(cookies):
project = cookies.bake()
assert project.exit_code == 0
assert project.exception is None
cwd = os.getcwd()
os.chdir(str(project.project))
try:
sh.python(['setup.py', 'install'])
except sh.ErrorReturnCode as e:
pytest.fail(e)
finally:
os.chdir(cwd)
示例7: test_building_documentation_apidocs
# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import fail [as 别名]
def test_building_documentation_apidocs(cookies):
project = cookies.bake(extra_context={'apidoc': 'yes'})
assert project.exit_code == 0
assert project.exception is None
cwd = os.getcwd()
os.chdir(str(project.project))
try:
sh.python(['setup.py', 'build_sphinx'])
except sh.ErrorReturnCode as e:
pytest.fail(e)
finally:
os.chdir(cwd)
apidocs = project.project.join('docs', '_build', 'html', 'apidocs')
assert apidocs.join('my_python_project.html').isfile()
assert apidocs.join('my_python_project.my_python_project.html').isfile()
示例8: test_orphaned_components
# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import fail [as 别名]
def test_orphaned_components(simple_linear_model):
model = simple_linear_model
model.nodes["Input"].max_flow = ConstantParameter(model, 10.0)
result = model.find_orphaned_parameters()
assert(not result)
# assert that warning not raised by check
with pytest.warns(None) as record:
model.check()
for w in record:
if isinstance(w, OrphanedParameterWarning):
pytest.fail("OrphanedParameterWarning raised unexpectedly!")
# add some orphans
orphan1 = ConstantParameter(model, 5.0)
orphan2 = ConstantParameter(model, 10.0)
orphans = {orphan1, orphan2}
result = model.find_orphaned_parameters()
assert(orphans == result)
with pytest.warns(OrphanedParameterWarning):
model.check()
示例9: test_log_returns
# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import fail [as 别名]
def test_log_returns():
s1 = Stream([200.23, 198.35, 244.36, 266.30, 250.40], "price")
assert s1.name == "price"
lp = s1.log()
lr = lp - lp.lag()
feed = DataFeed([lr])
feed.compile()
while feed.has_next():
print(feed.next())
lr = s1.log().diff().rename("log_return")
feed = DataFeed([lr])
feed.compile()
while feed.has_next():
print(feed.next())
# pytest.fail("Failed.")
示例10: test_multisig_to_redeemscript_too_long
# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import fail [as 别名]
def test_multisig_to_redeemscript_too_long(self):
# Maximum is 15 compressed keys in a multisig:
try:
public_keys = [b'\x00' * 33] * 15
multisig_to_redeemscript(public_keys, 1)
except ValueError: # pragma: no cover
pytest.fail("multisig_to_redeemscript did not accept 15 compressed public keys.")
public_keys = [b'\x00' * 33] * 16
with pytest.raises(ValueError):
multisig_to_redeemscript(public_keys, 1)
# Maximum is 7 uncompressed keys in a multisig
try:
public_keys = [b'\x00' * 65] * 7
multisig_to_redeemscript(public_keys, 1)
except ValueError: # pragma: no cover
pytest.fail("multisig_to_redeemscript did not accept 7 uncompressed public keys.")
public_keys = [b'\x00' * 65] * 8
with pytest.raises(ValueError):
multisig_to_redeemscript(public_keys, 1)
示例11: _runTest
# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import fail [as 别名]
def _runTest(self):
self._linter.check([self._test_file.module])
expected_messages, expected_text = self._get_expected()
received_messages, received_text = self._get_received()
if expected_messages != received_messages:
msg = ['Wrong results for file "%s":' % (self._test_file.base)]
missing, unexpected = multiset_difference(expected_messages,
received_messages)
if missing:
msg.append('\nExpected in testdata:')
msg.extend(' %3d: %s' % msg for msg in sorted(missing))
if unexpected:
msg.append('\nUnexpected in testdata:')
msg.extend(' %3d: %s' % msg for msg in sorted(unexpected))
pytest.fail('\n'.join(msg))
self._check_output_text(expected_messages, expected_text, received_text)
示例12: test_default
# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import fail [as 别名]
def test_default(ruleset, test, destaddr):
"""
Default tester with no logger obj. Useful for HTML contains and Status code
Not useful for testing loggers
"""
runner = testrunner.TestRunner()
try:
last_ua = http.HttpUA()
for stage in test.stages:
if destaddr is not None:
stage.input.dest_addr = destaddr
if stage.input.save_cookie:
runner.run_stage(stage, http_ua=last_ua)
else:
runner.run_stage(stage, logger_obj=None, http_ua=None)
except errors.TestError as e:
e.args[1]['meta'] = ruleset.meta
pytest.fail('Failure! Message -> {0}, Context -> {1}'.format(
e.args[0], e.args[1]))
示例13: test_default
# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import fail [as 别名]
def test_default(ruleset, test, destaddr, port, protocol):
"""
Default tester with no logger obj. Useful for HTML contains and Status code
Not useful for testing loggers
"""
runner = testrunner.TestRunner()
try:
for stage in test.stages:
if destaddr is not None:
stage.input.dest_addr = destaddr
if port is not None:
stage.input.port = port
if protocol is not None:
stage.input.protocol = protocol
runner.run_stage(stage, None)
except errors.TestError as e:
e.args[1]['meta'] = ruleset.meta
pytest.fail('Failure! Message -> {0}, Context -> {1}'.format(
e.args[0], e.args[1]))
示例14: emit
# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import fail [as 别名]
def emit(self, record):
logger = logging.getLogger(record.name)
root_logger = logging.getLogger()
if logger.name == 'messagemock':
return
if (logger.level == record.levelno or
root_logger.level == record.levelno):
# caplog.at_level(...) was used with the level of this message,
# i.e. it was expected.
return
if record.levelno < self._min_level:
return
pytest.fail("Got logging message on logger {} with level {}: "
"{}!".format(record.name, record.levelname,
record.getMessage()))
示例15: test_results_with_error
# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import fail [as 别名]
def test_results_with_error(conn_cnx):
"""Gets results with error."""
with conn_cnx() as cnx:
cur = cnx.cursor()
sfqid = None
try:
cur.execute("select blah")
pytest.fail("Should fail here!")
except ProgrammingError as e:
sfqid = e.sfqid
got_sfqid = None
try:
cur.query_result(sfqid)
pytest.fail("Should fail here again!")
except ProgrammingError as e:
got_sfqid = e.sfqid
assert got_sfqid is not None
assert got_sfqid == sfqid