
import os
import sys
from unittest import TestLoader, TestSuite, TextTestRunner

topdir = os.path.split(os.path.abspath(__file__))[0]
os.chdir(topdir)

loader = TestLoader()

if sys.version_info[:2] < (3, 0):
    tests = loader.discover('.', 'test_*.py')
elif sys.version_info[:2] > (3, 2):
    tests = TestSuite()
    tests.addTests(loader.discover('.', 'test_marshal.py'))
    tests.addTests(loader.discover('.', 'test_message.py'))
else:
    tests = TestSuite()

runner = TextTestRunner(verbosity=1, buffer=True)
runner.run(tests)


import os
import sys
from unittest import TestLoader, TestSuite, TextTestRunner

topdir = os.path.split(os.path.abspath(__file__))[0]
os.chdir(topdir)

loader = TestLoader()

if sys.version_info < (3, 0):
    tests = loader.discover('.', 'test_*.py')
elif sys.version_info > (3, 2):
    tests = TestSuite()
    tests.addTests(loader.discover('.', 'test_marshal.py'))
    tests.addTests(loader.discover('.', 'test_message.py'))
else:
    tests = TestSuite()

runner = TextTestRunner(verbosity=2, buffer=True)
result = runner.run(tests)

sys.exit(not result.wasSuccessful())

Exit non-zero if tests fail
Exit non-zero if tests fail

runtests.py was exiting 0 if test either failed or passed (which
confused tox, travis, etc).

Determine the status code based on the success of the test suite run.

  
  import os
  import sys
  from unittest import TestLoader, TestSuite, TextTestRunner
  
  topdir = os.path.split(os.path.abspath(__file__))[0]
  os.chdir(topdir)
  
  loader = TestLoader()
  
- if sys.version_info[:2] < (3, 0):
+ if sys.version_info < (3, 0):
      tests = loader.discover('.', 'test_*.py')
- elif sys.version_info[:2] > (3, 2):
+ elif sys.version_info > (3, 2):
      tests = TestSuite()
      tests.addTests(loader.discover('.', 'test_marshal.py'))
      tests.addTests(loader.discover('.', 'test_message.py'))
  else:
      tests = TestSuite()
  
- runner = TextTestRunner(verbosity=1, buffer=True)
+ runner = TextTestRunner(verbosity=2, buffer=True)
- runner.run(tests)
+ result = runner.run(tests)
  
+ sys.exit(not result.wasSuccessful())
+ 
Exit non-zero if tests fail
## Code Before:

import os
import sys
from unittest import TestLoader, TestSuite, TextTestRunner

topdir = os.path.split(os.path.abspath(__file__))[0]
os.chdir(topdir)

loader = TestLoader()

if sys.version_info[:2] < (3, 0):
    tests = loader.discover('.', 'test_*.py')
elif sys.version_info[:2] > (3, 2):
    tests = TestSuite()
    tests.addTests(loader.discover('.', 'test_marshal.py'))
    tests.addTests(loader.discover('.', 'test_message.py'))
else:
    tests = TestSuite()

runner = TextTestRunner(verbosity=1, buffer=True)
runner.run(tests)

## Instruction:
Exit non-zero if tests fail
## Code After:

import os
import sys
from unittest import TestLoader, TestSuite, TextTestRunner

topdir = os.path.split(os.path.abspath(__file__))[0]
os.chdir(topdir)

loader = TestLoader()

if sys.version_info < (3, 0):
    tests = loader.discover('.', 'test_*.py')
elif sys.version_info > (3, 2):
    tests = TestSuite()
    tests.addTests(loader.discover('.', 'test_marshal.py'))
    tests.addTests(loader.discover('.', 'test_message.py'))
else:
    tests = TestSuite()

runner = TextTestRunner(verbosity=2, buffer=True)
result = runner.run(tests)

sys.exit(not result.wasSuccessful())
