Skip to content

Instantly share code, notes, and snippets.

@jobovy
Last active August 29, 2015 14:12
Show Gist options
  • Save jobovy/05b711288da43ae7e29d to your computer and use it in GitHub Desktop.
Save jobovy/05b711288da43ae7e29d to your computer and use it in GitHub Desktop.
Show python3 warnings for specific module when running a test suite with nose
# Run this as
# python -3 MODULE TESTFILE NOSETESTS_OPTIONS
# where:
# MODULE: module that you want to check for python3 compatibility
# TESTFILE: file with tests
# NOSETESTS OPTIONS: other options that you would give to nosetests (e.g., -v, -x, --nocapture)
import sys
import warnings
import nose
if __name__ == '__main__':
module= sys.argv[1]
testfile= sys.argv[2]
warnings.filterwarnings('ignore','',DeprecationWarning,'^((?!%s).)*$' % module)
# Following line turns the warnings into errors
warnings.filterwarnings('error','',DeprecationWarning,module)
argv= ['blahblah',testfile] #nose.main ignores argv[0]
argv.extend(sys.argv[3:])
nose.main(argv=argv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment