import sys
from os.path import abspath
from os.path import dirname

# Load Django-related settings; necessary for tests to run and for Django
# imports to work.
import local_settings


from django.test.simple import DjangoTestSuiteRunner

def runtests():
    parent_dir = dirname(abspath(__file__))
    sys.path.insert(0, parent_dir)

    test_runner = DjangoTestSuiteRunner(
        verbosity=1,
        interactive=False,
        failfast=False)
    failures = test_runner.run_tests(['djoauth2'])
    sys.exit(failures)

if __name__ == '__main__':
    runtests()

import sys
from argparse import ArgumentParser
from os.path import abspath
from os.path import dirname

# Load Django-related settings; necessary for tests to run and for Django
# imports to work.
import local_settings
# Now, imports from Django will work properly without raising errors related to
# missing or badly-configured settings.

from django.test.simple import DjangoTestSuiteRunner

def runtests(verbosity, failfast, interactive, test_labels):
  # Modify the path so that our djoauth2 app is in it.
  parent_dir = dirname(abspath(__file__))
  sys.path.insert(0, parent_dir)

  test_runner = DjangoTestSuiteRunner(
      verbosity=verbosity,
      interactive=interactive,
      failfast=failfast)

  sys.exit(test_runner.run_tests(test_labels))

if __name__ == '__main__':
  # Parse any command line arguments.
  parser = ArgumentParser()
  parser.add_argument('--failfast',
                      action='store_true',
                      default=False,
                      dest='failfast')
  parser.add_argument('--interactive',
                      action='store_true',
                      default=False,
                      dest='interactive')
  parser.add_argument('--verbosity', default=1, type=int)
  parser.add_argument('test_labels', nargs='*', default=('djoauth2',))

  args = parser.parse_args()

  # Run the tests.
  runtests(args.verbosity, args.failfast, args.interactive, args.test_labels)

Allow testing of specific apps.
Allow testing of specific apps.

  import sys
+ from argparse import ArgumentParser
  from os.path import abspath
  from os.path import dirname
  
  # Load Django-related settings; necessary for tests to run and for Django
  # imports to work.
  import local_settings
- 
+ # Now, imports from Django will work properly without raising errors related to
+ # missing or badly-configured settings.
  
  from django.test.simple import DjangoTestSuiteRunner
  
- def runtests():
+ def runtests(verbosity, failfast, interactive, test_labels):
+   # Modify the path so that our djoauth2 app is in it.
-     parent_dir = dirname(abspath(__file__))
+   parent_dir = dirname(abspath(__file__))
-     sys.path.insert(0, parent_dir)
+   sys.path.insert(0, parent_dir)
  
-     test_runner = DjangoTestSuiteRunner(
+   test_runner = DjangoTestSuiteRunner(
-         verbosity=1,
+       verbosity=verbosity,
-         interactive=False,
+       interactive=interactive,
-         failfast=False)
+       failfast=failfast)
-     failures = test_runner.run_tests(['djoauth2'])
-     sys.exit(failures)
+ 
+   sys.exit(test_runner.run_tests(test_labels))
  
  if __name__ == '__main__':
-     runtests()
+   # Parse any command line arguments.
+   parser = ArgumentParser()
+   parser.add_argument('--failfast',
+                       action='store_true',
+                       default=False,
+                       dest='failfast')
+   parser.add_argument('--interactive',
+                       action='store_true',
+                       default=False,
+                       dest='interactive')
+   parser.add_argument('--verbosity', default=1, type=int)
+   parser.add_argument('test_labels', nargs='*', default=('djoauth2',))
  
+   args = parser.parse_args()
+ 
+   # Run the tests.
+   runtests(args.verbosity, args.failfast, args.interactive, args.test_labels)
+ 
Allow testing of specific apps.
## Code Before:
import sys
from os.path import abspath
from os.path import dirname

# Load Django-related settings; necessary for tests to run and for Django
# imports to work.
import local_settings


from django.test.simple import DjangoTestSuiteRunner

def runtests():
    parent_dir = dirname(abspath(__file__))
    sys.path.insert(0, parent_dir)

    test_runner = DjangoTestSuiteRunner(
        verbosity=1,
        interactive=False,
        failfast=False)
    failures = test_runner.run_tests(['djoauth2'])
    sys.exit(failures)

if __name__ == '__main__':
    runtests()

## Instruction:
Allow testing of specific apps.
## Code After:
import sys
from argparse import ArgumentParser
from os.path import abspath
from os.path import dirname

# Load Django-related settings; necessary for tests to run and for Django
# imports to work.
import local_settings
# Now, imports from Django will work properly without raising errors related to
# missing or badly-configured settings.

from django.test.simple import DjangoTestSuiteRunner

def runtests(verbosity, failfast, interactive, test_labels):
  # Modify the path so that our djoauth2 app is in it.
  parent_dir = dirname(abspath(__file__))
  sys.path.insert(0, parent_dir)

  test_runner = DjangoTestSuiteRunner(
      verbosity=verbosity,
      interactive=interactive,
      failfast=failfast)

  sys.exit(test_runner.run_tests(test_labels))

if __name__ == '__main__':
  # Parse any command line arguments.
  parser = ArgumentParser()
  parser.add_argument('--failfast',
                      action='store_true',
                      default=False,
                      dest='failfast')
  parser.add_argument('--interactive',
                      action='store_true',
                      default=False,
                      dest='interactive')
  parser.add_argument('--verbosity', default=1, type=int)
  parser.add_argument('test_labels', nargs='*', default=('djoauth2',))

  args = parser.parse_args()

  # Run the tests.
  runtests(args.verbosity, args.failfast, args.interactive, args.test_labels)
