本文整理汇总了Python中twisted.trial.unittest.main方法的典型用法代码示例。如果您正苦于以下问题:Python unittest.main方法的具体用法?Python unittest.main怎么用?Python unittest.main使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.trial.unittest
的用法示例。
在下文中一共展示了unittest.main方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_unittest_expected_failure_for_failing_test_is_xfail
# 需要导入模块: from twisted.trial import unittest [as 别名]
# 或者: from twisted.trial.unittest import main [as 别名]
def test_unittest_expected_failure_for_failing_test_is_xfail(testdir, runner):
script = testdir.makepyfile(
"""
import unittest
class MyTestCase(unittest.TestCase):
@unittest.expectedFailure
def test_failing_test_is_xfail(self):
assert False
if __name__ == '__main__':
unittest.main()
"""
)
if runner == "pytest":
result = testdir.runpytest("-rxX")
result.stdout.fnmatch_lines(
["*XFAIL*MyTestCase*test_failing_test_is_xfail*", "*1 xfailed*"]
)
else:
result = testdir.runpython(script)
result.stderr.fnmatch_lines(["*1 test in*", "*OK*(expected failures=1)*"])
assert result.ret == 0
示例2: test_unittest_expected_failure_for_passing_test_is_fail
# 需要导入模块: from twisted.trial import unittest [as 别名]
# 或者: from twisted.trial.unittest import main [as 别名]
def test_unittest_expected_failure_for_passing_test_is_fail(testdir, runner):
script = testdir.makepyfile(
"""
import unittest
class MyTestCase(unittest.TestCase):
@unittest.expectedFailure
def test_passing_test_is_fail(self):
assert True
if __name__ == '__main__':
unittest.main()
"""
)
if runner == "pytest":
result = testdir.runpytest("-rxX")
result.stdout.fnmatch_lines(
["*MyTestCase*test_passing_test_is_fail*", "*1 failed*"]
)
else:
result = testdir.runpython(script)
result.stderr.fnmatch_lines(["*1 test in*", "*(unexpected successes=1)*"])
assert result.ret == 1
示例3: test_importMain
# 需要导入模块: from twisted.trial import unittest [as 别名]
# 或者: from twisted.trial.unittest import main [as 别名]
def test_importMain(self):
"""Trying to import __main__"""
self.client.setZero()
self.p.perspective_do("import __main__")
if self.client.getMessages():
msg = self.client.getMessages()[0]
if msg[0] in ("exception","stderr"):
self.fail(msg[1])
#if __name__=='__main__':
# unittest.main()
示例4: test_djangolike_testcase
# 需要导入模块: from twisted.trial import unittest [as 别名]
# 或者: from twisted.trial.unittest import main [as 别名]
def test_djangolike_testcase(testdir):
# contributed from Morten Breekevold
testdir.makepyfile(
"""
from unittest import TestCase, main
class DjangoLikeTestCase(TestCase):
def setUp(self):
print("setUp()")
def test_presetup_has_been_run(self):
print("test_thing()")
self.assertTrue(hasattr(self, 'was_presetup'))
def tearDown(self):
print("tearDown()")
def __call__(self, result=None):
try:
self._pre_setup()
except (KeyboardInterrupt, SystemExit):
raise
except Exception:
import sys
result.addError(self, sys.exc_info())
return
super(DjangoLikeTestCase, self).__call__(result)
try:
self._post_teardown()
except (KeyboardInterrupt, SystemExit):
raise
except Exception:
import sys
result.addError(self, sys.exc_info())
return
def _pre_setup(self):
print("_pre_setup()")
self.was_presetup = True
def _post_teardown(self):
print("_post_teardown()")
"""
)
result = testdir.runpytest("-s")
assert result.ret == 0
result.stdout.fnmatch_lines(
[
"*_pre_setup()*",
"*setUp()*",
"*test_thing()*",
"*tearDown()*",
"*_post_teardown()*",
]
)