为什么coverage.py不正确地测量Django的runserver命令? [英] Why doesn't coverage.py properly measure Django's runserver command?

查看:196
本文介绍了为什么coverage.py不正确地测量Django的runserver命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该知道这个答案,但是我不这样做:如果你试图测量这样一个Django项目的覆盖面:

 code>覆盖运行manage.py runserver 

您可以获得错过所有实际码。在此过程中的一些事情是停止测量,或者所有的真实工作都发生在一个根本无法衡量的新环境中。



有人可以指出我在测量过程中的特定点出现故障,以便我可以尝试修复coverage.py,以便它可以按照人们期望的方式正确地测量它。

解决方案

如果您运行如下,您是否遇到同样的问题?

  coverage run manage.py runserver --noreload 

没有 - noreload 幕后开始了另一个过程。一个进程运行服务器,另一个进程查找代码更改,并在进行更改时重新启动服务器。可能的是,您正在监控过程而不是投放流程进行覆盖。



查看 django / core / management / commands / runserver.py django / utils / autoreload.py



更新:我运行了coverage命令,然后使用 ps lsof 来查看发生了什么。这是我观察到的:

  ps输出:

UID PID PPID C STIME TTY TIME CMD

vinay 12081 2098 0 16:37 pts / 0 00:00:00 /home/vinay/.virtualenvs/watfest/bin/python /home/vinay/.virtualenvs/watfest/bin/coverage run manage。 py runserver
vinay 12082 12081 2 16:37 pts / 0 00:00:01 /home/vinay/.virtualenvs/watfest/bin/python manage.py runserver

lsof输出:

python 12082 vinay 5u IPv4 48294 0t0 TCP localhost:8000(LISTEN)

IOW,即使在任何重新加载之前,有两个进程,一个在TCP端口上侦听的并不是那个覆盖运行的那个。



这是我看到的 - noreload

  ps输出:

UID PID PPID C STIME TTY TIME CMD

vinay 12140 2098 5 16:44 pts / 0 00:00:00 /home/vinay/.virtualenvs/watfest/bin/python / home / vinay / .virtualenvs / watfest / bin / coverage运行manage.py runserver --noreload

lsof输出:

coverage 12140 vinay 4u IPv4 51995 0t0 TCP localhost:8000(LISTEN )

所以不清楚为什么覆盖率不会在 noreload case。在我对 - noreload 的简短测试中,我得到了我的视图代码的覆盖,如下所示:

  festival / __ init__ 8 7 13%
管理9 4 56%
设置33 1 97%
pre>

I should know the answer to this, but I don't: if you try to measure the coverage of a Django project like this:

coverage run manage.py runserver 

you get coverage measurement that misses all of your actual code. Something early on in the process is stopping the measurement, or all the real work happens in a new context that doesn't get measured at all.

Can someone point me to the specific point in the process where the measurement breaks down, so that I can try to fix coverage.py so that it will measure it properly the way people expect?

解决方案

Do you get the same problem if you run as follows?

coverage run manage.py runserver --noreload

Without --noreload, another process is started behind the scenes. One process runs the server, the other looks for code changes and restarts the server when changes are made. The chances are, you're doing the coverage run on the monitoring process rather than the serving process.

Look at django/core/management/commands/runserver.py and django/utils/autoreload.py.

Update: I ran the coverage command, then used ps and lsof to look at what was happening. Here's what I observed:

ps output:

UID        PID  PPID  C STIME TTY          TIME CMD

vinay    12081  2098  0 16:37 pts/0    00:00:00 /home/vinay/.virtualenvs/watfest/bin/python /home/vinay/.virtualenvs/watfest/bin/coverage run manage.py runserver
vinay    12082 12081  2 16:37 pts/0    00:00:01 /home/vinay/.virtualenvs/watfest/bin/python manage.py runserver

lsof output:

python    12082      vinay    5u     IPv4      48294      0t0        TCP localhost:8000 (LISTEN)

IOW, even before any reloading there are two processes, and the one listening on the TCP port is not the one which coverage is running on.

Here's what I see with --noreload:

ps output:

UID        PID  PPID  C STIME TTY          TIME CMD

vinay    12140  2098  5 16:44 pts/0    00:00:00 /home/vinay/.virtualenvs/watfest/bin/python /home/vinay/.virtualenvs/watfest/bin/coverage run manage.py runserver --noreload

lsof output:

coverage  12140      vinay    4u     IPv4      51995      0t0        TCP localhost:8000 (LISTEN)

So it's not obvious why coverage wouldn't work in the --noreload case. In my very brief test with --noreload, I got coverage of my view code, as shown by the following extract:

festival/__init__   8      7    13%
manage              9      4    56%
settings           33      1    97%

这篇关于为什么coverage.py不正确地测量Django的runserver命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆