编写和运行测试。ImportError:没有名为generi的模块

2024-05-21 04:52:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我不熟悉tests in Django。我需要写一对。在

Django 1.9.7版。 操作系统:Linux version 4.2.0-42-generic (buildd@lgw01-54) (gcc version 5.2.1 20151010 (Ubuntu 5.2.1-22ubuntu2) ) #49-Ubuntu SMP Tue Jun 28 21:26:26 UTC 2016

我的简单测试代码是:

cat animal/tests.py

from django.test import TestCase
from animal.models import Animal 

class AnimalTestCase(TestCase):
    def say_hello(self):
        print('Hello, World!')

我是这样执行的./manage.py test animal

出现以下错误:

^{pr2}$

我做错什么了?在


Tags: djangoinfrompytestimportversionubuntu
2条回答

您安装的django autofixture版本不支持django1.9,因为它的GenericRelation的导入已过期。在

请尝试升级到最新版本。该项目的changelist表示django1.9支持是在版本0.11.0中添加的。在

为了让Django在您的AnimalTestCase中运行您的方法,您需要重命名它,使其以test_开头:

class AnimalTestCase(TestCase):
    def test_say_hello(self):
        print('Hello, World!')

您的导入错误,正确的导入来自

django.contrib.contenttypes.fields import GenericRelation

但这似乎实际上来自django汽车配件,而不是您自己的代码。好消息是这种简单的测试不需要自动夹具。就跟它说再见吧。在

相关问题 更多 >