Index: sascomp
===================================================================
--- sascomp	(revision 6708a6a1d1edd3ff91e14ee2497f44886a785de4)
+++ sascomp	(revision 424fe00c428dbe537e7616afc49f2450cc8bbc69)
@@ -19,5 +19,5 @@
 
     import sasmodels.compare
-    sasmodels.compare.main()
+    sasmodels.compare.main(*sys.argv[1:])
 
 if __name__ == "__main__":
Index: sasmodels/compare.py
===================================================================
--- sasmodels/compare.py	(revision a557a997158a33cbb8e8ef063dd6b3eb8a8d17c4)
+++ sasmodels/compare.py	(revision 424fe00c428dbe537e7616afc49f2450cc8bbc69)
@@ -777,26 +777,26 @@
 
 
-def parse_opts():
-    # type: () -> Dict[str, Any]
+def parse_opts(argv):
+    # type: (List[str]) -> Dict[str, Any]
     """
     Parse command line options.
     """
     MODELS = core.list_models()
-    flags = [arg for arg in sys.argv[1:]
+    flags = [arg for arg in argv
              if arg.startswith('-')]
-    values = [arg for arg in sys.argv[1:]
+    values = [arg for arg in argv
               if not arg.startswith('-') and '=' in arg]
-    args = [arg for arg in sys.argv[1:]
+    positional_args = [arg for arg in argv
             if not arg.startswith('-') and '=' not in arg]
     models = "\n    ".join("%-15s"%v for v in MODELS)
-    if len(args) == 0:
+    if len(positional_args) == 0:
         print(USAGE)
         print("\nAvailable models:")
         print(columnize(MODELS, indent="  "))
-        sys.exit(1)
-    if len(args) > 3:
+        return None
+    if len(positional_args) > 3:
         print("expected parameters: model N1 N2")
 
-    name = args[0]
+    name = positional_args[0]
     try:
         model_info = core.load_model_info(name)
@@ -804,5 +804,5 @@
         print(str(exc))
         print("Could not find model; use one of:\n    " + models)
-        sys.exit(1)
+        return None
 
     invalid = [o[1:] for o in flags
@@ -811,5 +811,5 @@
     if invalid:
         print("Invalid options: %s"%(", ".join(invalid)))
-        sys.exit(1)
+        return None
 
 
@@ -886,6 +886,6 @@
         del engines[2:]
 
-    n1 = int(args[1]) if len(args) > 1 else 1
-    n2 = int(args[2]) if len(args) > 2 else 1
+    n1 = int(positional_args[1]) if len(positional_args) > 1 else 1
+    n2 = int(positional_args[2]) if len(positional_args) > 2 else 1
     use_sasview = any(engine == 'sasview' and count > 0
                       for engine, count in zip(engines, [n1, n2]))
@@ -904,5 +904,5 @@
             s = set(p.split('_pd')[0] for p in pars)
             print("%r invalid; parameters are: %s"%(k, ", ".join(sorted(s))))
-            sys.exit(1)
+            return None
         presets[k] = float(v) if not k.endswith('type') else v
 
@@ -1036,15 +1036,16 @@
 
 
-def main():
-    # type: () -> None
+def main(*argv):
+    # type: (*str) -> None
     """
     Main program.
     """
-    opts = parse_opts()
-    if opts['explore']:
-        explore(opts)
-    else:
-        compare(opts)
+    opts = parse_opts(argv)
+    if opts is not None:
+        if opts['explore']:
+            explore(opts)
+        else:
+            compare(opts)
 
 if __name__ == "__main__":
-    main()
+    main(*sys.argv[1:])
Index: sasmodels/compare_many.py
===================================================================
--- sasmodels/compare_many.py	(revision 40a87fa5096610e24c3ead10299f609e99f093f2)
+++ sasmodels/compare_many.py	(revision 424fe00c428dbe537e7616afc49f2450cc8bbc69)
@@ -229,30 +229,30 @@
     print_models()
 
-def main():
+def main(argv):
     """
     Main program.
     """
-    if len(sys.argv) not in (6, 7):
+    if len(argv) not in (5, 6):
         print_help()
-        sys.exit(1)
-
-    model = sys.argv[1]
+        return
+
+    model = argv[0]
     if not (model in MODELS) and (model != "all"):
         print('Bad model %s.  Use "all" or one of:'%model)
         print_models()
-        sys.exit(1)
+        return
     try:
-        count = int(sys.argv[2])
-        is2D = sys.argv[3].startswith('2d')
-        assert sys.argv[3][1] == 'd'
-        Nq = int(sys.argv[3][2:])
-        mono = sys.argv[4] == 'mono'
-        cutoff = float(sys.argv[4]) if not mono else 0
-        base = sys.argv[5]
-        comp = sys.argv[6] if len(sys.argv) > 6 else "sasview"
+        count = int(argv[1])
+        is2D = argv[2].startswith('2d')
+        assert argv[2][1] == 'd'
+        Nq = int(argv[2][2:])
+        mono = argv[3] == 'mono'
+        cutoff = float(argv[3]) if not mono else 0
+        base = argv[4]
+        comp = argv[5] if len(argv) > 5 else "sasview"
     except Exception:
         traceback.print_exc()
         print_usage()
-        sys.exit(1)
+        return
 
     data, index = make_data({'qmax':1.0, 'is2d':is2D, 'nq':Nq, 'res':0.,
@@ -265,4 +265,4 @@
 if __name__ == "__main__":
     #from .compare import push_seed
-    #with push_seed(1): main()
-    main()
+    #with push_seed(1): main(sys.argv[1:])
+    main(sys.argv[1:])
