views:

93

answers:

2

When running nosetests from the command line, how do you specify that 'non-ignored' warnings should be treated as errors?

By default, warnings are printed, but not counted as failures:

[snip]/service/accounts/database.py:151: SADeprecationWarning: Use session.add()
  self.session.save(state)
[snip]/service/accounts/database.py:97: SADeprecationWarning: Use session.add()
  self.session.save(user)
............
----------------------------------------------------------------------
Ran 12 tests in 0.085s

OK

As we don't want our code to generate warnings, I don't want this situation to be OK.

Thanks!

Edit: Ideally what I'd like is a nosetests command line option that issues a warnings.simplefilter('error') prior to each test (and cleans it out afterwards).

Any solution that involves using the warnings module in the test code seems to defeat the point. I don't want to manually edit each test module to transform warnings into errors. Plus I don't want the author of each test module to be able to forget to 'turn on' warning errors.

A: 

I don't think nose can directly control this: the warnings module doesn't raise an exception when the warning is issued. The warnings module gives you control over which warnings should be raised as exceptions.

Ned Batchelder
A: 

I'm not sure about this, but is there a way to "catch" warnings... like a try/except kinda thing? Might be worth looking into...

inspectorG4dget