Django 不使用manage.py test 运行测试,除非指定了应用程序和特定的测试方法

发布于 2024-10-06 22:48:15 字数 577 浏览 0 评论 0原文

我有一个 Django 应用程序 myApp。其中有一个tests.py 文件,它使用 django.test.TestCase 类定义了许多测试用例。例如,其中之一称为WebViews,并且有一个测试方法check_status_codes。

当我运行 ./manage.py test 时,数据库是用我的初始数据构建的,但随后它告诉我它运行了 0 个测试。如果我这样做,我会得到类似的结果(测试未运行):

./manage.py 测试 myApp

甚至这个:

./manage.py 测试 myApp.WebViews

但是,如果我执行

./manage.py test.WebViews.check_status_codes

然后该确切的测试方法按预期运行。

我可以像这样将一堆测试方法串在一起并让它们运行,但这变得非常乏味,而且我有一种感觉我错过了一些东西。

关于做什么的任何提示或建议?

谢谢!

I have a Django application, myApp. In it, there's a tests.py file which defines a number of test cases using django.test.TestCase class. For example, one of them is called WebViews, and has a test method check_status_codes.

When I run ./manage.py test, the database is built with my initial data, but then it tells me that it ran 0 tests. I get similar results (tests not running) if I do this:

./manage.py test myApp

or even this:

./manage.py test myApp.WebViews

However, if I execute

./manage.py test.WebViews.check_status_codes

then that exact test method runs as expected.

I can string bunch of test methods together like this and get them to run, but this gets very tedious and I have a feeling I'm missing something.

Any hints or suggestions regarding what to do?

Thanks!

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

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

发布评论

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

评论(1

岁月打碎记忆 2024-10-13 22:48:15

我相信单元测试的惯例是让你的测试方法预先加上 test。例如:

class FooTest(TestCase):

    def setUp(self):
        # do setup stuff here
        pass

    def tearDown(self):
        # do teardown here
        pass

    def test_one_equals_one(self):
        self.assertEqual(1, 1, "One did not equal 1")

I believe the convention with unit tests is to have your test methods pre-pended with test. For example:

class FooTest(TestCase):

    def setUp(self):
        # do setup stuff here
        pass

    def tearDown(self):
        # do teardown here
        pass

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