gpt4 book ai didi

python - 关闭 nosetests 中的 sqlalchemy 警告

转载 作者:太空狗 更新时间:2023-10-30 00:08:01 26 4
gpt4 key购买 nike

我试图在使用 nosetests 运行我的测试套件时抑制所有 sqlalchemy 警告。我读了Turn off a warning in sqlalchemy

.............................../Users/ca/.pythonbrew/venvs/Python-2.7.3/api/lib/python2.7/site-packages/SQLAlchemy-0.7.5-py2.7-macosx-10.7-x86_64.egg/sqlalchemy/engine/default.py:330: Warning: Field 'random_id' doesn't have a default value
cursor.execute(statement, parameters)

我将其包含在我的包的 __init__.py 文件中:

def setup_package():
"""Setup the test during the whole session.

Run by nosetests
"""
# Suppress all SQLAlchemy warnings
warnings.filterwarnings("ignore", category=sa_exc.SAWarning)

通过适当的导入。我知道它是由 nosetests 运行的,因为我尝试了一些其他引发错误的东西。唯一的是,它没有任何效果。仍然显示警告。

有什么想法吗?

谢谢!

最佳答案

nose 似乎覆盖了你设置的任何内容:

warnings.filterwarnings("ignore")

但是,您可以使用 nose 的命令行选项在 nose 测试期间过滤警告。例如:

$ nosetests --logging-filter=SAWarning

我发现这可能在所有情况下都不起作用。如果是这种情况,您可以尝试:

$ python -W ignore `which nosetests`

关于python - 关闭 nosetests 中的 sqlalchemy 警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11577644/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com