本文整理汇总了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)))
示例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),
))
示例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)))
示例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))
示例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)]))
示例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())
示例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())
示例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())
示例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())
示例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())
示例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())
示例12: tearDown
# 需要导入模块: import testtools [as 别名]
# 或者: from testtools import TestCase [as 别名]
def tearDown(self):
super(TestCase, self).tearDown()
示例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)
示例14: setUp
# 需要导入模块: import testtools [as 别名]
# 或者: from testtools import TestCase [as 别名]
def setUp(self):
super(TestCase, self).setUp()
self.addCleanup(mock.patch.stopall)
示例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