微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何为 E2E 测试包含 Python 实用程序的覆盖率

如何解决如何为 E2E 测试包含 Python 实用程序的覆盖率

我有一个类似的python模块

TEST/testClass.py
class testClass.py:
     def __init__(self):
         <code>
     def fun1(self):
         <code>
     def fun2(self):
         print("executed")
         <code>

Utility: Util.py
import testClass.py
obj = testClass()
obj.fun1()
obj.fun2()

E2E tests:
from  subprocess import Popen
import unittest
class Test:
    def test_exec(self):
        Popen(["Util.py"],stdout=PIPE,stderr=PIPE,cwd=exeDir,shell=shell)
        (stdoutdata,stderrdata) = popenHandle.communicate()
        output = stdoutdata.decode('utf-8') + stderrdata.decode('utf-8')
        self.assertRegex(output,rf"executed")

if __name__ == '__main__':
   unittest.main()

#1: 那么在运行端到端测试时,如何为 testClass.py 和 Utils.py 生成 stmt、分支和功能覆盖率 现有的覆盖模块不考虑 Utils 和 testClass 进行覆盖计算,因为我们在 Popen 下运行该实用程序。无论如何要在 Utils.py 中包含一些开关(类似于使用 $HARnesS_PERL_SWITCHES 的 perl E2E 测试)以在 E2E 测试期间包含 python 覆盖率。

#2:功能覆盖也无法通过覆盖模块报告获得。如何获得python的功能覆盖?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。