本文整理匯總了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()*",
]
)