如何判断nosetest何时以编程方式运行
nosetest 是 Turbogeras 2.0 中的默认测试框架。该应用程序有一个用于初始化数据库的 websetup.py 模块。我在开发和生产环境中使用 mysql,并且 websetup 工作正常,但是 nosetest 在内存上使用 sqlite,当它尝试初始化数据库时会发送错误:
类型错误:SQLite 日期、时间和 DateTime 类型仅接受 Python 日期时间对象作为输入。
我已经检测到这种情况何时发生,并且处于导入阶段:
csvreader = csv.reader(open('res/products.csv'), delimiter=",", quotechar="'")
for row in csvreader:
p = model.Product(row[1], row[2], row[3], row[4] + ".jpg")
# Even tried to convert the date to a sqlalchemy type
# need to put a conditional here, when testing I don't care this date
import sqlalchemy
dateadded = sqlalchemy.types.DateTime(row[5])
p.dateAdded = dateadded
p.brand_id = row[6]
p.code = row[3]
ccat = model.DBSession.query(model.Category)\
.filter(model.Category.id==int(row[8]) + 3).one()
p.categories.append(ccat)
p.normalPrice = row[9]
p.specialPrice = row[10]
p.discountPrice = row[11]
model.DBSession.add(p)
How can I告诉nosetest何时运行?我尝试过:
if globals().has_key('ModelTest'):
第
if vars().has_key('ModelTest'):
一个没有结果,第二个有错误
nosetest is the default test framework in Turbogeras 2.0. The application has a websetup.py module that initialise the database. I use mysql for my development and production environment and websetup works fine, but nosetest uses sqlite on memory and when it tries to initialise the DB sends an error:
TypeError: SQLite Date, Time, and
DateTime types only accept Python
datetime objects as input.
I've detected when this happens and is in the import fase:
csvreader = csv.reader(open('res/products.csv'), delimiter=",", quotechar="'")
for row in csvreader:
p = model.Product(row[1], row[2], row[3], row[4] + ".jpg")
# Even tried to convert the date to a sqlalchemy type
# need to put a conditional here, when testing I don't care this date
import sqlalchemy
dateadded = sqlalchemy.types.DateTime(row[5])
p.dateAdded = dateadded
p.brand_id = row[6]
p.code = row[3]
ccat = model.DBSession.query(model.Category)\
.filter(model.Category.id==int(row[8]) + 3).one()
p.categories.append(ccat)
p.normalPrice = row[9]
p.specialPrice = row[10]
p.discountPrice = row[11]
model.DBSession.add(p)
How can I tell when nosetest is running? I've try:
if globals().has_key('ModelTest'):
and
if vars().has_key('ModelTest'):
The first one with no results and the second one with error
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据推测,如果nose正在运行,“nose”顶级模块将被导入。您应该能够使用“
当然这不是一个万无一失的测试”来测试它,它假设没有其他原因导致鼻子被导入。
Presumably if nose is running, the 'nose' top-level module will have been imported. You should be able to test that with
Of course this is not a foolproof test, which assumes that there's no other reason why nose would be imported.
我不使用 TurboGears,但是是否没有设置或全局某处表明测试正在运行?在大型系统中,运行测试时通常需要进行一些小的更改。 SQLite 和 MySQL 之间的切换只是一个例子。
I don't use TurboGears, but is there not a setting or global somewhere that indicates that the tests are running? In large systems, there are often small changes that need to be made when running tests. Switching between SQLite and MySQL is just one example.