import os
import sys
import contextlib
import subprocess


@contextlib.contextmanager
def binding(binding):
    """Prepare an environment for a specific binding"""

    sys.stderr.write("""\
#
# Running tests with %s..
#
""" % binding)

    os.environ["QT_PREFERRED_BINDING"] = binding

    try:
        yield
    except:
        pass

    os.environ.pop("QT_PREFERRED_BINDING")


if __name__ == "__main__":
    argv = [
        "nosetests",
        "--verbose",
        "--with-process-isolation",
        "--exe",
    ]

    # argv.extend(sys.argv[1:])

    # Running each test independently via subprocess
    # enables tests to filter out from tests.py before
    # being split into individual processes via the
    # --with-process-isolation feature of nose.
    with binding("PyQt4"):
        subprocess.call(argv)

    with binding("PySide"):
        subprocess.call(argv)

    with binding("PyQt5"):
        subprocess.call(argv)

    with binding("PySide2"):
        subprocess.call(argv)

import os
import sys
import contextlib
import subprocess


@contextlib.contextmanager
def binding(binding):
    """Prepare an environment for a specific binding"""

    sys.stderr.write("""\
#
# Running tests with %s..
#
""" % binding)

    os.environ["QT_PREFERRED_BINDING"] = binding

    try:
        yield
    except:
        pass

    os.environ.pop("QT_PREFERRED_BINDING")


if __name__ == "__main__":
    argv = [
        "nosetests",
        "--verbose",
        "--with-process-isolation",
        "--exe",
    ]

    errors = 0

    # Running each test independently via subprocess
    # enables tests to filter out from tests.py before
    # being split into individual processes via the
    # --with-process-isolation feature of nose.
    with binding("PyQt4"):
        errors += subprocess.call(argv)

    with binding("PySide"):
        errors += subprocess.call(argv)

    with binding("PyQt5"):
        errors += subprocess.call(argv)

    with binding("PySide2"):
        errors += subprocess.call(argv)

    if errors:
        raise Exception("%i binding(s) failed." % errors)

Throw exception when primary tests fail
Throw exception when primary tests fail

  import os
  import sys
  import contextlib
  import subprocess
  
  
  @contextlib.contextmanager
  def binding(binding):
      """Prepare an environment for a specific binding"""
  
      sys.stderr.write("""\
  #
  # Running tests with %s..
  #
  """ % binding)
  
      os.environ["QT_PREFERRED_BINDING"] = binding
  
      try:
          yield
      except:
          pass
  
      os.environ.pop("QT_PREFERRED_BINDING")
  
  
  if __name__ == "__main__":
      argv = [
          "nosetests",
          "--verbose",
          "--with-process-isolation",
          "--exe",
      ]
  
-     # argv.extend(sys.argv[1:])
+     errors = 0
  
      # Running each test independently via subprocess
      # enables tests to filter out from tests.py before
      # being split into individual processes via the
      # --with-process-isolation feature of nose.
      with binding("PyQt4"):
-         subprocess.call(argv)
+         errors += subprocess.call(argv)
  
      with binding("PySide"):
-         subprocess.call(argv)
+         errors += subprocess.call(argv)
  
      with binding("PyQt5"):
-         subprocess.call(argv)
+         errors += subprocess.call(argv)
  
      with binding("PySide2"):
-         subprocess.call(argv)
+         errors += subprocess.call(argv)
  
+     if errors:
+         raise Exception("%i binding(s) failed." % errors)
+ 
Throw exception when primary tests fail
## Code Before:
import os
import sys
import contextlib
import subprocess


@contextlib.contextmanager
def binding(binding):
    """Prepare an environment for a specific binding"""

    sys.stderr.write("""\
#
# Running tests with %s..
#
""" % binding)

    os.environ["QT_PREFERRED_BINDING"] = binding

    try:
        yield
    except:
        pass

    os.environ.pop("QT_PREFERRED_BINDING")


if __name__ == "__main__":
    argv = [
        "nosetests",
        "--verbose",
        "--with-process-isolation",
        "--exe",
    ]

    # argv.extend(sys.argv[1:])

    # Running each test independently via subprocess
    # enables tests to filter out from tests.py before
    # being split into individual processes via the
    # --with-process-isolation feature of nose.
    with binding("PyQt4"):
        subprocess.call(argv)

    with binding("PySide"):
        subprocess.call(argv)

    with binding("PyQt5"):
        subprocess.call(argv)

    with binding("PySide2"):
        subprocess.call(argv)

## Instruction:
Throw exception when primary tests fail
## Code After:
import os
import sys
import contextlib
import subprocess


@contextlib.contextmanager
def binding(binding):
    """Prepare an environment for a specific binding"""

    sys.stderr.write("""\
#
# Running tests with %s..
#
""" % binding)

    os.environ["QT_PREFERRED_BINDING"] = binding

    try:
        yield
    except:
        pass

    os.environ.pop("QT_PREFERRED_BINDING")


if __name__ == "__main__":
    argv = [
        "nosetests",
        "--verbose",
        "--with-process-isolation",
        "--exe",
    ]

    errors = 0

    # Running each test independently via subprocess
    # enables tests to filter out from tests.py before
    # being split into individual processes via the
    # --with-process-isolation feature of nose.
    with binding("PyQt4"):
        errors += subprocess.call(argv)

    with binding("PySide"):
        errors += subprocess.call(argv)

    with binding("PyQt5"):
        errors += subprocess.call(argv)

    with binding("PySide2"):
        errors += subprocess.call(argv)

    if errors:
        raise Exception("%i binding(s) failed." % errors)
