當前位置: 首頁>>代碼示例>>Python>>正文


Python unittest.main方法代碼示例

本文整理匯總了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 
開發者ID:pytest-dev,項目名稱:pytest,代碼行數:23,代碼來源:test_unittest.py

示例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 
開發者ID:pytest-dev,項目名稱:pytest,代碼行數:25,代碼來源:test_unittest.py

示例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() 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:13,代碼來源:test_manhole.py

示例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()*",
        ]
    ) 
開發者ID:pytest-dev,項目名稱:pytest,代碼行數:58,代碼來源:test_unittest.py


注:本文中的twisted.trial.unittest.main方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。