这是一个测试:
@skip("my test is skipped")
def test_coverage():
my_function()
我的问题很简单:
如果我执行我的承保范围,my_function
是否会被承保(考虑我的测试被跳过)?
谢谢!
答案 0 :(得分:1)
不执行跳过的测试。根据定义,未涵盖未执行的代码。
演示;给定_
模块:
coverage_demo
和def foo():
var = "This function has is covered"
def bar():
var = "This function is not"
文件:
coverage_demo_tests.py
在覆盖范围内运行此操作会显示from unittest import TestCase, skip
import coverage_demo
class DemoTests(TestCase):
def test_foo(self):
coverage_demo.foo()
@skip("No bar for us today")
def test_bar(self):
import coverage_demo
coverage_demo.bar()
if __name__ == '__main__':
import unittest
unittest.main()
中的第5行未执行:
coverage_demo
始终执行顶级$ coverage run coverage_demo_tests.py
s.
----------------------------------------------------------------------
Ran 2 tests in 0.000s
OK (skipped=1)
$ coverage report --include=coverage_demo\.py -m
Name Stmts Miss Cover Missing
------------------------------------------------
coverage_demo.py 4 1 75% 5
语句,但第5行是def
函数中的唯一一行。