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


Python testtools.TestCase方法代碼示例

本文整理匯總了Python中testtools.TestCase方法的典型用法代碼示例。如果您正苦於以下問題:Python testtools.TestCase方法的具體用法?Python testtools.TestCase怎麽用?Python testtools.TestCase使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在testtools的用法示例。


在下文中一共展示了testtools.TestCase方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_successful_flaky_test

# 需要導入模塊: import testtools [as 別名]
# 或者: from testtools import TestCase [as 別名]
def test_successful_flaky_test(self):
        """
        A successful flaky test is considered successful.
        """

        # We use 'testtools' here to avoid accidentally depending on Twisted
        # TestCase features, thus increasing complexity.
        class SomeTest(testtools.TestCase):

            run_tests_with = retry_flaky()

            @flaky(u'FLOC-XXXX')
            def test_something(self):
                pass

        test = SomeTest('test_something')
        self.assertThat(run_test(test), has_results(tests_run=Equals(1))) 
開發者ID:ClusterHQ,項目名稱:flocker,代碼行數:19,代碼來源:test_flaky.py

示例2: test_intermittent_flaky_test_that_errors

# 需要導入模塊: import testtools [as 別名]
# 或者: from testtools import TestCase [as 別名]
def test_intermittent_flaky_test_that_errors(self, test_methods):
        """
        Tests marked with 'flaky' are retried if they fail, and marked as
        erroring / failing if they don't reach the minimum number of successes.
        """
        executions = iter(test_methods)

        class SomeTest(testtools.TestCase):
            run_tests_with = retry_flaky()

            @flaky(u'FLOC-XXXX', max_runs=len(test_methods), min_passes=2)
            def test_something(self):
                next(executions)()

        test = SomeTest('test_something')
        self.assertThat(run_test(test), has_results(
            tests_run=Equals(1),
            errors=HasLength(1),
        )) 
開發者ID:ClusterHQ,項目名稱:flocker,代碼行數:21,代碼來源:test_flaky.py

示例3: test_intermittent_flaky_subclass

# 需要導入模塊: import testtools [as 別名]
# 或者: from testtools import TestCase [as 別名]
def test_intermittent_flaky_subclass(self, test_methods):
        """
        We sometimes subclass test classes in order to test different
        implementations of the same interface. A test within such a subclass
        can be marked as flaky, causing it to retry.
        """
        executions = iter(test_methods)

        class SomeTest(testtools.TestCase):
            run_tests_with = retry_flaky()

            def test_something(self):
                next(executions)()

        class SubclassTest(SomeTest):

            @flaky(u'FLOC-XXXX', max_runs=len(test_methods), min_passes=1)
            def test_something(self):
                super(SubclassTest, self).test_something()

        test = SubclassTest('test_something')
        self.assertThat(run_test(test), has_results(tests_run=Equals(1))) 
開發者ID:ClusterHQ,項目名稱:flocker,代碼行數:24,代碼來源:test_flaky.py

示例4: test_flaky_testtools_skipped_test

# 需要導入模塊: import testtools [as 別名]
# 或者: from testtools import TestCase [as 別名]
def test_flaky_testtools_skipped_test(self, jira_keys, max_runs,
                                          min_passes, reasons):
        """
        If a test is skipped and also marked @flaky, we report it as skipped.
        """
        [min_passes, max_runs] = sorted([min_passes, max_runs])
        observed_reasons = []

        class SkippingTest(testtools.TestCase):
            run_tests_with = retry_flaky()

            @flaky(jira_keys, max_runs, min_passes)
            def test_skip(self):
                observed_reasons.append(reasons.next())
                self.skip(observed_reasons[-1])

        test = SkippingTest('test_skip')
        self.assertThat(run_test(test), only_skips(1, observed_reasons)) 
開發者ID:ClusterHQ,項目名稱:flocker,代碼行數:20,代碼來源:test_flaky.py

示例5: test_sends_start_on_start

# 需要導入模塊: import testtools [as 別名]
# 或者: from testtools import TestCase [as 別名]
def test_sends_start_on_start(self, jira_keys):
        """
        Flaky tests send ``startTest`` as soon as they start.

        This means that we see the name of the test in the trial reporter
        (FLOC-3511) and that the recorded duration of the test is more-or-less
        accurate (FLOC-3499)
        """
        log = []

        class FlakyTest(testtools.TestCase):
            run_tests_with = retry_flaky()

            @flaky(jira_keys, 1, 1)
            def test_delayed(self):
                # Get a copy of the event log at this point of the test.
                self.log = list(log)

        test = FlakyTest('test_delayed')
        result = ExtendedTestResult(log)
        test.run(result)
        self.assertThat(test.log, Equals([('startTest', test)])) 
開發者ID:ClusterHQ,項目名稱:flocker,代碼行數:24,代碼來源:test_flaky.py

示例6: setUp

# 需要導入模塊: import testtools [as 別名]
# 或者: from testtools import TestCase [as 別名]
def setUp(self):
        "Run before each test method to initialize test environment."

        super(TestCase, self).setUp()
        test_timeout = os.environ.get('OS_TEST_TIMEOUT', 0)
        try:
            test_timeout = int(test_timeout)
        except ValueError:
            # If timeout value is invalid do not set a timeout.
            test_timeout = 0
        if test_timeout > 0:
            self.useFixture(fixtures.Timeout(test_timeout, gentle=True))

        self.useFixture(fixtures.NestedTempfile())
        self.useFixture(fixtures.TempHomeDir())

        if os.environ.get('OS_STDOUT_CAPTURE') in _TRUE_VALUES:
            stdout = self.useFixture(fixtures.StringStream('stdout')).stream
            self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout))
        if os.environ.get('OS_STDERR_CAPTURE') in _TRUE_VALUES:
            stderr = self.useFixture(fixtures.StringStream('stderr')).stream
            self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr))

        self.log_fixture = self.useFixture(fixtures.FakeLogger()) 
開發者ID:softwarefactory-project,項目名稱:DLRN,代碼行數:26,代碼來源:base.py

示例7: test_failedSaysSo

# 需要導入模塊: import testtools [as 別名]
# 或者: from testtools import TestCase [as 別名]
def test_failedSaysSo(self):
        """
        A failing test case causes the whole run to report 'FAILED'
        """
        sub_tmpdir = tempfile.mkdtemp(dir=self.tmpdir)
        fh = open(os.path.join(sub_tmpdir, "test_failed.py"), "w")
        fh.write(
            dedent(
                """
            import unittest
            class Failed(unittest.TestCase):
                def test01(self):
                    self.assertTrue(False)
            """.format(
                    os.getpid()
                )
            )
        )
        fh.close()
        os.chdir(sub_tmpdir)
        tests = self.loader.loadTargets("test_failed")
        result = run(tests, self.stream, self.args)
        os.chdir(self.startdir)
        self.assertEqual(result.testsRun, 1)
        self.assertIn("FAILED", self.stream.getvalue()) 
開發者ID:CleanCut,項目名稱:green,代碼行數:27,代碼來源:test_runner.py

示例8: setUp

# 需要導入模塊: import testtools [as 別名]
# 或者: from testtools import TestCase [as 別名]
def setUp(self):
        """Run before each test method to initialize test environment."""

        super(TestCase, self).setUp()
        test_timeout = os.environ.get('OS_TEST_TIMEOUT', 0)
        try:
            test_timeout = int(test_timeout)
        except ValueError:
            # If timeout value is invalid do not set a timeout.
            test_timeout = 0
        if test_timeout > 0:
            self.useFixture(fixtures.Timeout(test_timeout, gentle=True))

        self.useFixture(fixtures.NestedTempfile())
        self.useFixture(fixtures.TempHomeDir())

        if os.environ.get('OS_STDOUT_CAPTURE') in _TRUE_VALUES:
            stdout = self.useFixture(fixtures.StringStream('stdout')).stream
            self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout))
        if os.environ.get('OS_STDERR_CAPTURE') in _TRUE_VALUES:
            stderr = self.useFixture(fixtures.StringStream('stderr')).stream
            self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr))

        self.log_fixture = self.useFixture(fixtures.FakeLogger()) 
開發者ID:openstack,項目名稱:bashate,代碼行數:26,代碼來源:base.py

示例9: setUp

# 需要導入模塊: import testtools [as 別名]
# 或者: from testtools import TestCase [as 別名]
def setUp(self):
        """Run before each test method to initialize test environment."""

        super(TestCase, self).setUp()
        test_timeout = os.environ.get('OS_TEST_TIMEOUT', 0)
        try:
            test_timeout = int(test_timeout)
        except ValueError:
            # If timeout value is invalid do not set a timeout.
            test_timeout = 0
        if test_timeout > 0:
            self.useFixture(fixtures.Timeout(test_timeout, gentle=True))

        self.useFixture(fixtures.NestedTempfile())
        self.temp_homedir = self.useFixture(fixtures.TempHomeDir()).path

        if os.environ.get('OS_STDOUT_CAPTURE') in _TRUE_VALUES:
            stdout = self.useFixture(fixtures.StringStream('stdout')).stream
            self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout))
        if os.environ.get('OS_STDERR_CAPTURE') in _TRUE_VALUES:
            stderr = self.useFixture(fixtures.StringStream('stderr')).stream
            self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr))

        self.log_fixture = self.useFixture(fixtures.FakeLogger()) 
開發者ID:openstack,項目名稱:python-tripleoclient,代碼行數:26,代碼來源:base.py

示例10: setUp

# 需要導入模塊: import testtools [as 別名]
# 或者: from testtools import TestCase [as 別名]
def setUp(self):
        """Run before each test method to initialize test environment."""

        super(TestCase, self).setUp()
        test_timeout = os.environ.get('OS_TEST_TIMEOUT', 60)
        try:
            test_timeout = int(test_timeout)
        except ValueError:
            # If timeout value is invalid, set a default timeout.
            test_timeout = 60
        if test_timeout <= 0:
            test_timeout = 60
        self.useFixture(fixtures.Timeout(test_timeout, gentle=True))

        self.useFixture(fixtures.NestedTempfile())
        self.useFixture(fixtures.TempHomeDir())

        if os.environ.get('OS_STDOUT_CAPTURE') in _TRUE_VALUES:
            stdout = self.useFixture(fixtures.StringStream('stdout')).stream
            self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout))
        if os.environ.get('OS_STDERR_CAPTURE') in _TRUE_VALUES:
            stderr = self.useFixture(fixtures.StringStream('stderr')).stream
            self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr))

        self.log_fixture = self.useFixture(fixtures.FakeLogger()) 
開發者ID:openstack,項目名稱:python-magnumclient,代碼行數:27,代碼來源:base.py

示例11: setUp

# 需要導入模塊: import testtools [as 別名]
# 或者: from testtools import TestCase [as 別名]
def setUp(self):
        """Run before each test method to initialize test environment."""

        super(TestCase, self).setUp()
        self.stubbed_mapped_nics = {}

        def dummy_mapped_nics(nic_mapping=None):
            return self.stubbed_mapped_nics
        if self.stub_mapped_nics:
            self.stub_out('os_net_config.objects.mapped_nics',
                          dummy_mapped_nics)

        test_timeout = os.environ.get('OS_TEST_TIMEOUT', 0)
        try:
            test_timeout = int(test_timeout)
        except ValueError:
            # If timeout value is invalid do not set a timeout.
            test_timeout = 0
        if test_timeout > 0:
            self.useFixture(fixtures.Timeout(test_timeout, gentle=True))

        self.useFixture(fixtures.NestedTempfile())
        self.useFixture(fixtures.TempHomeDir())

        if os.environ.get('OS_STDOUT_CAPTURE') in _TRUE_VALUES:
            stdout = self.useFixture(fixtures.StringStream('stdout')).stream
            self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout))
        if os.environ.get('OS_STDERR_CAPTURE') in _TRUE_VALUES:
            stderr = self.useFixture(fixtures.StringStream('stderr')).stream
            self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr))

        self.log_fixture = self.useFixture(fixtures.FakeLogger()) 
開發者ID:openstack,項目名稱:os-net-config,代碼行數:34,代碼來源:base.py

示例12: tearDown

# 需要導入模塊: import testtools [as 別名]
# 或者: from testtools import TestCase [as 別名]
def tearDown(self):
        super(TestCase, self).tearDown() 
開發者ID:openstack,項目名稱:os-net-config,代碼行數:4,代碼來源:base.py

示例13: setUp

# 需要導入模塊: import testtools [as 別名]
# 或者: from testtools import TestCase [as 別名]
def setUp(self):
        super(TestCase, self).setUp()
        config.register_cli_opts()
        self.addCleanup(mock.patch.stopall)
        self.addCleanup(self.clean_caches) 
開發者ID:openstack,項目名稱:octavia,代碼行數:7,代碼來源:base.py

示例14: setUp

# 需要導入模塊: import testtools [as 別名]
# 或者: from testtools import TestCase [as 別名]
def setUp(self):
        super(TestCase, self).setUp()
        self.addCleanup(mock.patch.stopall) 
開發者ID:boris-42,項目名稱:profimp,代碼行數:5,代碼來源:test.py

示例15: mktemp

# 需要導入模塊: import testtools [as 別名]
# 或者: from testtools import TestCase [as 別名]
def mktemp(self):
        """
        Create a temporary path for use in tests.

        Provided for compatibility with Twisted's ``TestCase``.

        :return: Path to non-existent file or directory.
        """
        return self.make_temporary_path().path 
開發者ID:ClusterHQ,項目名稱:flocker,代碼行數:11,代碼來源:_base.py


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