我目前正在测试我的数据库可访问性,但遇到了一个严重的问题。我正在模拟数据库并插入一个具有注册日期的用户对象。该日期首先写入一个变量,然后传递给应产生完全相同值的数据。嗯,它不...数据文件class User(Document): email = EmailField(required=True) first_name = StringField(max_length=50) last_name = StringField(required=True, max_length=50) registration_date = DateTimeField(default=datetime.utcnow()) last_login = DateTimeField()test_storage.pyimport datetimeimport pytestfrom mongoengine.connection import ( connect, get_connection,)from mongodb.data import Userfrom storage.users import get_usersFMT = "%Y-%m-%d %H:%M"@pytest.fixture(scope='module')def mock_db(): connect('mongoenginetest', host='mongomock://localhost')@pytest.fixture(scope='module')def mock_user(mock_db): user = { 'email': 'wijgowol@kogun.gi', 'registration_date': datetime.datetime.utcnow(), 'last_name': 'Bowen', 'first_name': 'Charlie', } db_user = User (**user) db_user.save() return user, db_userdef test_storage_get_user(mock_user): user, db_user = mock_user users = get_users() assert len(users) == 1 assert type(users[0]) == User u = users[0] assert u == db_user assert u.email == user['email'] assert u.registration_date == user['registration_date'] assert u.last_name == user['last_name'] assert u.first_name == user['first_name']当我运行测试时,我得到以下结果:_____________________________________________________________________________________________________________________ test_storage_get_user _____________________________________________________________________________________________________________________mock_user = ({'email': 'wijgowol@kogun.gi', 'first_name': 'Charlie', 'last_name': 'Bowen', 'registration_date': datetime.datetime(2018, 10, 4, 10, 49, 56, 814025)}, <User: User object>)def test_storage_get_user(mock_user): user, db_user = mock_user users = get_users() assert len(users) == 1 assert type(users[0]) == User为什么那里的时间不一样?
添加回答
举报
0/150
提交
取消