Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turn off sqlalchemy warnings in nosetests

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

I included this in my package's __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 the proper imports. I know it is run by nosetests because I tried some other stuff which raised error. The only thing is that it has no effect whatsoever. Warnings are still displayed.

Any idea?

Thanks!

like image 699
charlax Avatar asked Jul 20 '12 10:07

charlax


1 Answers

It seems that nose overwrites whatever you set with:

warnings.filterwarnings("ignore")

However you can filter warnings during nose test with a command line option to nose. e.g.:

$ nosetests --logging-filter=SAWarning

I found that this still may not work under all circumstances. If this is the case you can try:

$ python -W ignore `which nosetests`
like image 137
roman Avatar answered Oct 23 '22 07:10

roman