当前位置: 首页>>代码示例>>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;未经允许,请勿转载。