问题描述
我正在运行鼻子测试,它具有设置功能,该功能需要加载与生产数据库不同的数据库.我正在使用的ORM是peewee,它要求在定义中设置模型的数据库.
I'm running nosetests which have a setup function that needs to load a different database than the production database. The ORM I'm using is peewee which requires that the database for a model is set in the definition.
因此,我需要设置一个条件变量,但我不知道要使用什么条件来检查是否测试鼻子是否正在运行文件.
So I need to set a conditional variable but I don't know what condition to use in order to check if nosetest is running the file.
我在Stack Overflow上读到可以在sys.modules
中检查nose
的方法,但我想知道是否有更准确的方法来检查机头是否在运行.
I read on Stack Overflow that you can check for nose
in sys.modules
but I was wondering if there is a more exact way to check if nose is running.
推荐答案
也许检查sys.argv[0]
以查看正在运行什么命令?
Perhaps examining sys.argv[0]
to see what command is running?
这篇关于Python:基于是否运行鼻子测试的条件变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!