小编Wil*_* P.的帖子

Django:RunTimeWarning:DateTimeField在时区支持处于活动状态时收到了一个天真的日期时间

我正在尝试测试基于django cart的购物车创建

但是当我尝试创建购物车时出现此错误:

RunTimeWarning:DateTimeField在时区支持处于活动状态时收到了一个天真的日期时间

我做了一些研究,但我无法解决我的问题 datetime.datetime.now()

我的测试目录中的test_views.py:

from django.test import TestCase, Client, RequestFactory
import unittest
from django.contrib.auth.models import User, AnonymousUser
from front.models import Entreprise, Cart, CartItems
from decimal import Decimal
from front.cart import models
import datetime
import pytz
from pytz import all_timezones
from django.utils import timezone



def _create_cart_in_database(self, creationDate=datetime.datetime.now(), checkedOutDate=True):
    """
        Helper function so I don't repeat myself
    """
    cart = models.Cart()
    cart.creationDate = creationDate
    cart.checkedOutDate = False
    cart.save()
    return cart


def test_cart_creation(self):
    creationDate = datetime.datetime.now()
    cart = …
Run Code Online (Sandbox Code Playgroud)

python django

12
推荐指数
1
解决办法
3万
查看次数

Django测试unittest.loader.ModuleImportFailure

我无法在我的测试目录中导入模型,这是我的错误:

======================================================================
ERROR: tests.test_views (unittest.loader.ModuleImportFailure)
----------------------------------------------------------------------
ImportError: Failed to import test module: tests.test_views
Traceback (most recent call last):
  File "C:\Python27\lib\unittest\loader.py", line 254, in _find_tests
    module = self._get_module_from_name(name)
  File "C:\Python27\lib\unittest\loader.py", line 232, in _get_module_from_name
    __import__(name)
  File "c:\wamp\www\km0\tests\test_views.py", line 3, in <module>
    from .models import Entreprise
  File "c:\wamp\www\km0\tests\models.py", line 6, in <module>
    class Entreprise(models.Model):
  File "C:\Python27\lib\site-packages\django-1.9.5-py2.7.egg\django\db\models\ba
se.py", line 102, in __new__
    "INSTALLED_APPS." % (module, name)
RuntimeError: Model class tests.models.Entreprise doesn't declare an explicit ap
p_label and isn't in an application in INSTALLED_APPS. …
Run Code Online (Sandbox Code Playgroud)

python django unit-testing

5
推荐指数
1
解决办法
1919
查看次数

标签 统计

django ×2

python ×2

unit-testing ×1