import glob
import os
import unittest


def build_test_suite():
    suite = unittest.TestSuite()

    for test_case in glob.glob('tests/test_*.py'):
        modname = os.path.splitext(test_case)[0]
        modname = modname.replace('/', '.')
        module = __import__(modname, {}, {}, ['1'])
        suite.addTest(unittest.TestLoader().loadTestsFromModule(module))

    return suite


if __name__ == "__main__":
    suite = build_test_suite()
    runner = unittest.TextTestRunner()

    runner.run(suite)

import glob
import os
import unittest
import sys

def build_test_suite():
    suite = unittest.TestSuite()

    for test_case in glob.glob('tests/test_*.py'):
        modname = os.path.splitext(test_case)[0]
        modname = modname.replace('/', '.')
        module = __import__(modname, {}, {}, ['1'])
        suite.addTest(unittest.TestLoader().loadTestsFromModule(module))

    return suite


if __name__ == "__main__":
    suite = build_test_suite()
    runner = unittest.TextTestRunner()

    result = runner.run(suite)
    sys.exit(not result.wasSuccessful())

Make unittest return exit code 1 on failure
Make unittest return exit code 1 on failure

This is to allow travis to catch test failures

  import glob
  import os
  import unittest
- 
+ import sys
  
  def build_test_suite():
      suite = unittest.TestSuite()
  
      for test_case in glob.glob('tests/test_*.py'):
          modname = os.path.splitext(test_case)[0]
          modname = modname.replace('/', '.')
          module = __import__(modname, {}, {}, ['1'])
          suite.addTest(unittest.TestLoader().loadTestsFromModule(module))
  
      return suite
  
  
  if __name__ == "__main__":
      suite = build_test_suite()
      runner = unittest.TextTestRunner()
  
-     runner.run(suite)
+     result = runner.run(suite)
+     sys.exit(not result.wasSuccessful())
  
Make unittest return exit code 1 on failure
## Code Before:
import glob
import os
import unittest


def build_test_suite():
    suite = unittest.TestSuite()

    for test_case in glob.glob('tests/test_*.py'):
        modname = os.path.splitext(test_case)[0]
        modname = modname.replace('/', '.')
        module = __import__(modname, {}, {}, ['1'])
        suite.addTest(unittest.TestLoader().loadTestsFromModule(module))

    return suite


if __name__ == "__main__":
    suite = build_test_suite()
    runner = unittest.TextTestRunner()

    runner.run(suite)

## Instruction:
Make unittest return exit code 1 on failure
## Code After:
import glob
import os
import unittest
import sys

def build_test_suite():
    suite = unittest.TestSuite()

    for test_case in glob.glob('tests/test_*.py'):
        modname = os.path.splitext(test_case)[0]
        modname = modname.replace('/', '.')
        module = __import__(modname, {}, {}, ['1'])
        suite.addTest(unittest.TestLoader().loadTestsFromModule(module))

    return suite


if __name__ == "__main__":
    suite = build_test_suite()
    runner = unittest.TextTestRunner()

    result = runner.run(suite)
    sys.exit(not result.wasSuccessful())
