如何让unittest2和coverage.py一起工作?

发布于 2024-09-11 00:27:42 字数 243 浏览 9 评论 0原文

如何让 unittest2coverage.py 一起工作?

理论上类似的东西

coverage run unit2 discover 

应该可以工作,但目前它只是出错了。

如果您是 nose 用户,则相当于 nosetests --with-coverage

How can you get unittest2 and coverage.py working together?

In theory something like

coverage run unit2 discover 

should work, but it currently just errors out.

If you are a nose user that will be the equivalent of nosetests --with-coverage.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

别低头,皇冠会掉 2024-09-18 00:27:42

尝试:

coverage run -m unittest discover

对我有用。

Try:

coverage run -m unittest discover

works for me.

沉睡月亮 2024-09-18 00:27:42

这必须特定于您的安装,因为它对我来说可以很好地

coverage run unit2 discover

生成覆盖范围信息,然后

coverage html

生成 HTML 报告(几种报告格式之一)并

open htmlcov/index.html

查看结果。

(回答这个问题是因为这是“unittest2 覆盖率”的首要问题,我不希望人们因缺乏任何答案而被推迟。)

This must be specific to your installation since it works fine for me

coverage run unit2 discover

to generate the coverage information then

coverage html

to generate the an HTML report (one of several reporting formats), and

open htmlcov/index.html

to see the results.

(Answering this because this is a top ghit for "unittest2 coverage" and I don't want people put off by the lack of any answer.)

莫言歌 2024-09-18 00:27:42

我正在运行 Windows 并遇到了同样的问题。

$ coverage run unit2 discover
No file to run: 'unit2'

我怀疑这与不同操作系统上系统路径和Python路径处理方式的差异有关(我猜测Andrew正在运行Linux?)。无论如何,coverage run 采用 -m 选项,允许您运行模块而不是脚本。这就是我使用的:

coverage run -m unittest2 discover

I am running Windows and encountered the same problem.

$ coverage run unit2 discover
No file to run: 'unit2'

I suspect this is related to differences in how the system path and python path are handled on various operating systems (I'm guessing Andrew is running linux?). Regardless, coverage run takes a -m option which allows you to run a module rather than a script. This is what I use:

coverage run -m unittest2 discover
荒岛晴空 2024-09-18 00:27:42

如果您安装了多个版本的 coverage,请使用

coverage2 run -m unittest discover

coverage3 run -m unittest discover

指定要运行哪个版本。

In case you have multiple versions of coverage installed, use

coverage2 run -m unittest discover

or

coverage3 run -m unittest discover

to specify which one you're going to run.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文