【问题标题】:How to trace code coverage of scripts run in Python shell from an unit test?如何从单元测试跟踪在 Python shell 中运行的脚本的代码覆盖率?
【发布时间】:2019-07-10 04:07:09
【问题描述】:

我正在使用 Visual Studio Enterprise 来获取单元测试的代码覆盖率。单元测试将打开一个 Python shell 并执行其他 Python 脚本,例如,在 Python shell 中运行 execfile("other_script.py")。

但是,VS 不知道这个外部 Python shell 以及在那里调用的任何函数,因此它不会对在这个外部 Python shell 中运行的函数或脚本进行任何代码覆盖。

是否可以让 Visual Studio 也覆盖外部 Python shell 中运行的函数?

我所说的 Python shell 是指在 Windows 上运行 Python.exe 时将打开的窗口。

【问题讨论】:

    标签: python visual-studio unit-testing code-coverage


    【解决方案1】:

    如果您想运行其他脚本,请执行以下操作:

    import [script here]
    

    在此之前你也可以有不同的陈述。我还是不明白你的意思。你能解释更多吗?

    【讨论】:

    • 嗨,我在原始问题中添加了更多细节,希望它更清楚
    猜你喜欢
    • 1970-01-01
    • 2010-10-14
    • 1970-01-01
    • 1970-01-01
    • 2012-01-18
    • 2018-09-01
    • 2016-05-04
    相关资源
    最近更新 更多