为什么python报道说错过了线?

时间:2022-03-08 05:27:56

I'm trying to use coverage with Django, but I seem to be getting incorrect results. My app is named "stats" and I have this test:

我正在尝试使用Django覆盖,但我似乎得到了不正确的结果。我的应用名为“stats”,我有这个测试:

class ListSchoolsTest(TestCase):
    def test_initial_list(self):
        self.client.login(username='skeezy', password='skeezy')
        resp = self.client.get("/stats/list_schools/")
        self.assertEqual(resp.status_code, 200)

On the command line, I run:

在命令行中,我运行:

coverage run --source="." manage.py test stats

And the test passes. All my views are currently in stats/views.py

测试通过了。我的所有观点目前都在stats / views.py中

But when I run "coverage report", I get this line:

但是,当我运行“报道报告”时,我得到这一行:

Name                 Stmts   Miss  Cover
----------------------------------------
<snip>
stats/views            110    110     0%

Any idea what I am (not) doing that would cause coverage to report all lines missed in stats/views.py, even though it would have to be hit in order for the test to pass? (just as a belt-and-suspenders, I put a print statement in my view, and it's definitely getting hit.)

任何想法我(不)这样做会导致报告报告stats / views.py中遗漏的所有行,即使它必须被击中以便测试通过? (就像腰带和吊带一样,我在我的视图中放了一个印刷声明,它肯定会被击中。)

1 个解决方案

#1


0  

Maybe you have pip installed your app without the -e flag? Then the modules are not imported from your project directory but the path they were installed to and coverage thinks those are different files.

也许你有没有-e标志的pip安装你的应用程序?然后,模块不会从您的项目目录导入,但它们安装到的路径和coverage认为这些是不同的文件。

#1


0  

Maybe you have pip installed your app without the -e flag? Then the modules are not imported from your project directory but the path they were installed to and coverage thinks those are different files.

也许你有没有-e标志的pip安装你的应用程序?然后,模块不会从您的项目目录导入,但它们安装到的路径和coverage认为这些是不同的文件。