Disable sqlalchemy warnings in nosetests

I am trying to suppress all sqlalchemy warnings while running my test suite using nosetests. I read Disable 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) 

I included this in my package __init__.py file:

 def setup_package(): """Setup the test during the whole session. Run by nosetests """ # Suppress all SQLAlchemy warnings warnings.filterwarnings("ignore", category=sa_exc.SAWarning) 

With proper import. I know that it is controlled by nosetests because I tried some other things that caused the error. The only thing is that it has no effect. Alerts are still displayed.

Any idea?

Thanks!

+6
source share
1 answer

It seems like the nose overwrites everything you installed:

 warnings.filterwarnings("ignore") 

However, you can filter warnings during a nose test with a command line option for the nose. eg:.

 $ nosetests --logging-filter=SAWarning 

I found that this may still not work under any circumstances. If so, you can try:

 $ python -W ignore `which nosetests` 
+4
source

Source: https://habr.com/ru/post/920956/


All Articles