PyCharm没有测试所有Django测试

时间:2013-12-26 09:02:11

标签: django unit-testing pycharm django-testing

由于一些奇怪的原因我无法弄清楚,一旦我在PyCharm中的应用程序上运行测试,Pycharm将不会测试我添加的其他TestCases,即使我添加它们。

例如,下面我在我测试的模块中有一组测试,然后我添加了What测试用例并再次运行测试 - 但是根本没有运行新的测试! / p>

测试文件:

from django.test import TestCase
from django.contrib.staticfiles import finders
from django.contrib.staticfiles.storage import staticfiles_storage
import os

class SimpleTest(TestCase):
    def test_basic_addition(self):
        """
        Tests that 1 + 1 always equals 2.
        """
        self.assertEqual(1 + 1, 2)

class SettingsTest(TestCase):
    def settings_loaded(self):
        self.assertIsNotNone(os.getenv('DJANGO_SETTINGS_MODULE'))

class HomePageTestCase(TestCase):
    def test_index(self):
        resp = self.client.get('/')
        self.assertEqual(resp.status_code, 200)

    def static_loaded(self):
        abs_path = finders.find('bootstrap.css')
        self.assertTrue(staticfiles_storage.exists(abs_path))

    def get_favicon(self):
        # abs_path = finders.find('favicon.ico')
        resp=self.client.get('/static/favicon.ico')
        self.assertEqual(resp.status_code, 200)

class TeamPageCase(TestCase):
    def test_loads(self):
        resp = self.client.get('/team/')
        self.assertEqual(resp.status_code, 200)

class FAQPageCase(TestCase):
    def test_loads(self):
        resp=self.client.get('/faq/')
        self.assertEqual(resp.status_code, 200)

class What(TestCase):
    def doit(self):
        self.assertEqual(3,3)

在下面的屏幕截图中,您可以看到只运行了四个TestCases - 由于某种原因,第五个永远不会被触及。

PyCharm testing suite screenshot

为什么会这样?如何让PyCharm运行我的所有测试用例?我是否需要更新某些内容或运行某些testsync命令......或其他内容?

1 个答案:

答案 0 :(得分:2)

您的屏幕截图显示正在运行四个测试,您总共有八个测试。

正在运行的四个是您命名为def test_...的四个测试。

"A testcase is created by subclassing unittest.TestCase. The three individual tests are defined with methods whose names start with the letters test. This naming convention informs the test runner about which methods represent tests."

重命名前面没有test_运行的测试。