本文整理汇总了Python中logilab.common.pytest.SkipAwareTextTestRunner.run方法的典型用法代码示例。如果您正苦于以下问题:Python SkipAwareTextTestRunner.run方法的具体用法?Python SkipAwareTextTestRunner.run怎么用?Python SkipAwareTextTestRunner.run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类logilab.common.pytest.SkipAwareTextTestRunner
的用法示例。
在下文中一共展示了SkipAwareTextTestRunner.run方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ExitFirstTC
# 需要导入模块: from logilab.common.pytest import SkipAwareTextTestRunner [as 别名]
# 或者: from logilab.common.pytest.SkipAwareTextTestRunner import run [as 别名]
class ExitFirstTC(TestCase):
def setUp(self):
output = StringIO()
self.runner = SkipAwareTextTestRunner(stream=output, exitfirst=True)
def test_failure_exit_first(self):
class FooTC(TestCase):
def test_1(self):
pass
def test_2(self):
assert False
def test_3(self):
pass
tests = [FooTC("test_1"), FooTC("test_2")]
result = self.runner.run(TestSuite(tests))
self.assertEqual(result.testsRun, 2)
self.assertEqual(len(result.failures), 1)
self.assertEqual(len(result.errors), 0)
def test_error_exit_first(self):
class FooTC(TestCase):
def test_1(self):
pass
def test_2(self):
raise ValueError()
def test_3(self):
pass
tests = [FooTC("test_1"), FooTC("test_2"), FooTC("test_3")]
result = self.runner.run(TestSuite(tests))
self.assertEqual(result.testsRun, 2)
self.assertEqual(len(result.failures), 0)
self.assertEqual(len(result.errors), 1)
def test_generative_exit_first(self):
class FooTC(TestCase):
def test_generative(self):
for i in xrange(10):
yield self.assert_, False
result = self.runner.run(FooTC("test_generative"))
self.assertEqual(result.testsRun, 1)
self.assertEqual(len(result.failures), 1)
self.assertEqual(len(result.errors), 0)
示例2: TestLoaderTC
# 需要导入模块: from logilab.common.pytest import SkipAwareTextTestRunner [as 别名]
# 或者: from logilab.common.pytest.SkipAwareTextTestRunner import run [as 别名]
class TestLoaderTC(TestCase):
## internal classes for test purposes ########
class FooTC(TestCase):
def test_foo1(self): pass
def test_foo2(self): pass
def test_bar1(self): pass
class BarTC(TestCase):
def test_bar2(self): pass
##############################################
def setUp(self):
self.loader = NonStrictTestLoader()
self.module = TestLoaderTC # mock_object(FooTC=TestLoaderTC.FooTC, BarTC=TestLoaderTC.BarTC)
self.output = StringIO()
self.runner = SkipAwareTextTestRunner(stream=self.output)
def assertRunCount(self, pattern, module, expected_count, skipped=()):
self.loader.test_pattern = pattern
self.loader.skipped_patterns = skipped
if pattern:
suite = self.loader.loadTestsFromNames([pattern], module)
else:
suite = self.loader.loadTestsFromModule(module)
result = self.runner.run(suite)
self.loader.test_pattern = None
self.loader.skipped_patterns = ()
self.assertEqual(result.testsRun, expected_count)
def test_collect_everything(self):
"""make sure we don't change the default behaviour
for loadTestsFromModule() and loadTestsFromTestCase
"""
testsuite = self.loader.loadTestsFromModule(self.module)
self.assertEqual(len(testsuite._tests), 2)
suite1, suite2 = testsuite._tests
self.assertEqual(len(suite1._tests) + len(suite2._tests), 4)
def test_collect_with_classname(self):
self.assertRunCount('FooTC', self.module, 3)
self.assertRunCount('BarTC', self.module, 1)
def test_collect_with_classname_and_pattern(self):
data = [('FooTC.test_foo1', 1), ('FooTC.test_foo', 2), ('FooTC.test_fo', 2),
('FooTC.foo1', 1), ('FooTC.foo', 2), ('FooTC.whatever', 0)
]
for pattern, expected_count in data:
yield self.assertRunCount, pattern, self.module, expected_count
def test_collect_with_pattern(self):
data = [('test_foo1', 1), ('test_foo', 2), ('test_bar', 2),
('foo1', 1), ('foo', 2), ('bar', 2), ('ba', 2),
('test', 4), ('ab', 0),
]
for pattern, expected_count in data:
yield self.assertRunCount, pattern, self.module, expected_count
def test_testcase_with_custom_metaclass(self):
class mymetaclass(type): pass
class MyMod:
class MyTestCase(TestCase):
__metaclass__ = mymetaclass
def test_foo1(self): pass
def test_foo2(self): pass
def test_bar(self): pass
data = [('test_foo1', 1), ('test_foo', 2), ('test_bar', 1),
('foo1', 1), ('foo', 2), ('bar', 1), ('ba', 1),
('test', 3), ('ab', 0),
('MyTestCase.test_foo1', 1), ('MyTestCase.test_foo', 2),
('MyTestCase.test_fo', 2), ('MyTestCase.foo1', 1),
('MyTestCase.foo', 2), ('MyTestCase.whatever', 0)
]
for pattern, expected_count in data:
yield self.assertRunCount, pattern, MyMod, expected_count
def test_collect_everything_and_skipped_patterns(self):
testdata = [ (['foo1'], 3), (['foo'], 2),
(['foo', 'bar'], 0), ]
for skipped, expected_count in testdata:
yield self.assertRunCount, None, self.module, expected_count, skipped
def test_collect_specific_pattern_and_skip_some(self):
testdata = [ ('bar', ['foo1'], 2), ('bar', [], 2),
('bar', ['bar'], 0), ]
for runpattern, skipped, expected_count in testdata:
yield self.assertRunCount, runpattern, self.module, expected_count, skipped
def test_skip_classname(self):
testdata = [ (['BarTC'], 3), (['FooTC'], 1), ]
for skipped, expected_count in testdata:
yield self.assertRunCount, None, self.module, expected_count, skipped
def test_skip_classname_and_specific_collect(self):
testdata = [ ('bar', ['BarTC'], 1), ('foo', ['FooTC'], 0), ]
for runpattern, skipped, expected_count in testdata:
yield self.assertRunCount, runpattern, self.module, expected_count, skipped
def test_nonregr_dotted_path(self):
self.assertRunCount('FooTC.test_foo', self.module, 2)
#.........这里部分代码省略.........
示例3: GenerativeTestsTC
# 需要导入模块: from logilab.common.pytest import SkipAwareTextTestRunner [as 别名]
# 或者: from logilab.common.pytest.SkipAwareTextTestRunner import run [as 别名]
class GenerativeTestsTC(TestCase):
def setUp(self):
output = StringIO()
self.runner = SkipAwareTextTestRunner(stream=output)
def test_generative_ok(self):
class FooTC(TestCase):
def test_generative(self):
for i in xrange(10):
yield self.assertEqual, i, i
result = self.runner.run(FooTC('test_generative'))
self.assertEqual(result.testsRun, 10)
self.assertEqual(len(result.failures), 0)
self.assertEqual(len(result.errors), 0)
def test_generative_half_bad(self):
class FooTC(TestCase):
def test_generative(self):
for i in xrange(10):
yield self.assertEqual, i%2, 0
result = self.runner.run(FooTC('test_generative'))
self.assertEqual(result.testsRun, 10)
self.assertEqual(len(result.failures), 5)
self.assertEqual(len(result.errors), 0)
def test_generative_error(self):
class FooTC(TestCase):
def test_generative(self):
for i in xrange(10):
if i == 5:
raise ValueError('STOP !')
yield self.assertEqual, i, i
result = self.runner.run(FooTC('test_generative'))
self.assertEqual(result.testsRun, 5)
self.assertEqual(len(result.failures), 0)
self.assertEqual(len(result.errors), 1)
def test_generative_error2(self):
class FooTC(TestCase):
def test_generative(self):
for i in xrange(10):
if i == 5:
yield self.ouch
yield self.assertEqual, i, i
def ouch(self): raise ValueError('stop !')
result = self.runner.run(FooTC('test_generative'))
self.assertEqual(result.testsRun, 11)
self.assertEqual(len(result.failures), 0)
self.assertEqual(len(result.errors), 1)
def test_generative_setup(self):
class FooTC(TestCase):
def setUp(self):
raise ValueError('STOP !')
def test_generative(self):
for i in xrange(10):
yield self.assertEqual, i, i
result = self.runner.run(FooTC('test_generative'))
self.assertEqual(result.testsRun, 1)
self.assertEqual(len(result.failures), 0)
self.assertEqual(len(result.errors), 1)
def test_generative_inner_skip(self):
class FooTC(TestCase):
def check(self, val):
if val == 5:
self.innerSkip("no 5")
else:
self.assertEqual(val, val)
def test_generative(self):
for i in xrange(10):
yield InnerTest("check_%s"%i, self.check, i)
result = self.runner.run(FooTC('test_generative'))
self.assertEqual(result.testsRun, 10)
self.assertEqual(len(result.failures), 0)
self.assertEqual(len(result.errors), 0)
self.assertEqual(len(result.skipped), 1)
def test_generative_skip(self):
class FooTC(TestCase):
def check(self, val):
if val == 5:
self.skipTest("no 5")
else:
self.assertEqual(val, val)
def test_generative(self):
for i in xrange(10):
yield InnerTest("check_%s"%i, self.check, i)
result = self.runner.run(FooTC('test_generative'))
self.assertEqual(result.testsRun, 10)
self.assertEqual(len(result.failures), 0)
self.assertEqual(len(result.errors), 0)
self.assertEqual(len(result.skipped), 1)
#.........这里部分代码省略.........