为什么 Python 3.8.3 的单元测试覆盖被禁用?
Why is unittest coverage disabled for Python 3.8.3?
我有这个版本的 Python:
3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:37:02) [MSC v.1924 64 bit (AMD64)]
运行宁 Windows 10 在 PyCharm CE 2020.1.1。使用非常简单的 unittest
:
# test_simple.py
from unittest import TestCase
class Simple(TestCase):
def test_one(self):
self.assertTrue(True)
我可以运行 python -m coverage run -m unittest
,完成并生成一个.coverage
SQLite文件;我可以 运行 从 IDE 生成 Test Results 树的测试;但是 运行 / 运行 with Coverage 是灰色的,没有任何解释。
我已按照(相当分散的)PyCharm 文档进行设置/构建、执行、部署、激活覆盖视图 已启用,在将覆盖应用到编辑器之前显示选项 但这没有帮助。
为什么覆盖范围是灰色的,我该如何解决?
不幸的是,IDE 覆盖支持在 PyCharm 的社区版中不可用,如 the edition features.
中所示
您必须像往常一样在命令行上 运行 覆盖,例如 .
您还可以使用一些包装器来创建和打开 HTML 报告。在 this blog post 中可以找到使用具有覆盖率的 pytest 的此类包装器的示例。这是该博客中使用的脚本(请注意,我更改了覆盖路径以使用当前版本):
import os
import subprocess
import webbrowser
def main():
subprocess.call(['coverage', 'erase'])
subprocess.call(['coverage', 'run', '--module', 'pytest'])
subprocess.call(['coverage', 'html'])
webbrowser.open("file://" + os.getcwd() + "/htmlcov/index.html", new=2)
if __name__ == '__main__':
main()
我有这个版本的 Python:
3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:37:02) [MSC v.1924 64 bit (AMD64)]
运行宁 Windows 10 在 PyCharm CE 2020.1.1。使用非常简单的 unittest
:
# test_simple.py
from unittest import TestCase
class Simple(TestCase):
def test_one(self):
self.assertTrue(True)
我可以运行 python -m coverage run -m unittest
,完成并生成一个.coverage
SQLite文件;我可以 运行 从 IDE 生成 Test Results 树的测试;但是 运行 / 运行 with Coverage 是灰色的,没有任何解释。
我已按照(相当分散的)PyCharm 文档进行设置/构建、执行、部署、激活覆盖视图 已启用,在将覆盖应用到编辑器之前显示选项 但这没有帮助。
为什么覆盖范围是灰色的,我该如何解决?
不幸的是,IDE 覆盖支持在 PyCharm 的社区版中不可用,如 the edition features.
中所示您必须像往常一样在命令行上 运行 覆盖,例如
您还可以使用一些包装器来创建和打开 HTML 报告。在 this blog post 中可以找到使用具有覆盖率的 pytest 的此类包装器的示例。这是该博客中使用的脚本(请注意,我更改了覆盖路径以使用当前版本):
import os
import subprocess
import webbrowser
def main():
subprocess.call(['coverage', 'erase'])
subprocess.call(['coverage', 'run', '--module', 'pytest'])
subprocess.call(['coverage', 'html'])
webbrowser.open("file://" + os.getcwd() + "/htmlcov/index.html", new=2)
if __name__ == '__main__':
main()