停止抽象 django.test 测试用例 class 来自 运行 测试也

Stop abstract django.test TestCase class from running test also

我正在创建 Django 单元测试,并且有一些非常相似的模型具有重复的功能。然而,存在一些差异,所以我创建了一个抽象的 BaseTestCase class,其他 TestCase classes 继承自。它似乎工作正常,除了当从 BaseTestCase class 继承的 TestCases 完成 运行ning 他们的测试时,Django 仍将尝试 运行 BaseTestCase classes 测试也是如此。 Django 不应该不想 运行 抽象 BaseTestCase 上的测试吗?是否缺少某种类型的配置以确保不会发生这种情况?

测试用例布局

class BaseTestCase(SetupTestCase):
    api = ""

    def test_obj_list(self):
        response = self.client.get(self.api)

        self.assertTrue(response.status_code == 200)

    def test_obj_create(self):
        pass

    def test_obj_retrieve(self):
        pass

    def test_obj_update(self):
        pass

    def test_obj_delete(self):
        pass

    class Meta:
        abstract = True

class ChildTestCaseOne(BaseTestCase):
    api = "/api/v0.1/path_one/"

class ChildTestCaseTwo(BaseTestCase):
    api = "/api/v0.1/path_two/"

class ChildTestCaseThree(BaseTestCase):
    api = "/api/v0.1/path_three/"

class ChildTestCaseFour(BaseTestCase):
    api = "/api/v0.1/path_four/"

class ChildTestCaseFive(BaseTestCase):
    api = "/api/v0.1/path_five/"

这应该 运行 25 个测试,五个测试用例的五个测试,但它 运行s 30。之后 运行s 每个 child 的 5 个测试class,它 运行 也是基本测试用例的 5 个测试。

multiple inheritance呢?

from django.test import TestCase

class BaseTestCase:
    # ...

class ChildTestCaseN(BaseTestCase, TestCase):
    # ...

我在 Django 中找不到任何关于抽象测试用例的信息。你从哪里得到的 SetupTestCase class?