Repository: ManageIQ/integration_tests

Issue:
Freeze.py screws up test running
The virtualenv that is left in requirments/ dir seems to interfere with normal operations so I always need to delete it, perhaps we need some ignore somewhere or need to place it elsewhere

```
../default/lib/python2.7/site-packages/py/_path/common.py:367: in visit
    for x in Visitor(fil, rec, ignore, bf, sort).gen(self):
../default/lib/python2.7/site-packages/py/_path/common.py:416: in gen
    for p in self.gen(subdir):
../default/lib/python2.7/site-packages/py/_path/common.py:416: in gen
    for p in self.gen(subdir):
../default/lib/python2.7/site-packages/py/_path/common.py:416: in gen
    for p in self.gen(subdir):
../default/lib/python2.7/site-packages/py/_path/common.py:416: in gen
    for p in self.gen(subdir):
../default/lib/python2.7/site-packages/py/_path/common.py:416: in gen
    for p in self.gen(subdir):
../default/lib/python2.7/site-packages/py/_path/common.py:416: in gen
    for p in self.gen(subdir):
../default/lib/python2.7/site-packages/py/_path/common.py:416: in gen
    for p in self.gen(subdir):
../default/lib/python2.7/site-packages/py/_path/common.py:406: in gen
    if p.check(dir=1) and (rec is None or rec(p))])
../default/lib/python2.7/site-packages/_pytest/main.py:682: in _recurse
    ihook = self.gethookproxy(path)
../default/lib/python2.7/site-packages/_pytest/main.py:587: in gethookproxy
    my_conftestmodules = pm._getconftestmodules(fspath)
../default/lib/python2.7/site-packages/_pytest/config.py:339: in _getconftestmodules
    mod = self._importconftest(conftestpath)
../default/lib/python2.7/site-packages/_pytest/config.py:375: in _importconftest
    self.consider_conftest(mod)
../default/lib/python2.7/site-packages/_pytest/config.py:398: in consider_conftest
    if self.register(conftestmodule, name=conftestmodule.__file__):
../default/lib/python2.7/site-packages/_pytest/config.py:250: in register
    ret = super(PytestPluginManager, self).register(plugin, name)
../default/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py:371: in register
    hook._maybe_apply_history(hookimpl)
../default/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py:768: in _maybe_apply_history
    res = self._hookexec(self, [method], kwargs)
../default/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py:339: in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
../default/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py:334: in <lambda>
    _MultiCall(methods, kwargs, hook.spec_opts).execute()
../default/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py:614: in execute
    res = hook_impl.function(*args)
requirements/temporary_venv/lib/python2.7/site-packages/tests/contrib/appengine/conftest.py:45: in pytest_configure
    if config.getoption('gae_sdk') is not None:
../default/lib/python2.7/site-packages/_pytest/config.py:1195: in getoption
    raise ValueError("no option named %r" % (name,))
E   ValueError: no option named 'gae_sdk'
```


Discussion:

Resolving patch:
diff --git a/requirements/freeze.py b/requirements/freeze.py
--- a/requirements/freeze.py
+++ b/requirements/freeze.py
@@ -2,31 +2,52 @@
 """
 outputs the frozen packages
 """
+from __future__ import print_function
 import sys
 import os
 import argparse
 import subprocess
+import tempfile
+import shutil
 parser = argparse.ArgumentParser(description=__doc__.strip())
-parser.add_argument('--venv', default='requirements/temporary_venv')
+parser.add_argument('--venv', default=None)
+parser.add_argument('--keep-venv', action='store_true')
 parser.add_argument(
     "--template", default="requirements/template.txt",)
 parser.add_argument(
-    "--out", default=sys.stdout, type=argparse.FileType('w'),
+    "--out", default=None,
     help='the file where packages should be written to')
 
 
 def main(args):
-    if not os.path.isdir(args.venv):
+    if args.venv is None:
+        args.venv = tempfile.mkdtemp(suffix='-miq-QE-rebuild-venv')
+
+    try:
+        if not os.path.isdir(os.path.join(args.venv, 'bin')):
+            subprocess.check_call([
+                sys.executable, '-m', 'virtualenv', args.venv
+            ])
         subprocess.check_call([
-            sys.executable, '-m', 'virtualenv', args.venv
-        ])
-    subprocess.check_call([
-        os.path.join(args.venv, 'bin/pip'),
-        'install', '-U', '-r', args.template])
+            os.path.join(args.venv, 'bin/pip'),
+            'install', '-U', '-r', args.template])
+
+        if args.out is None:
+            subprocess.check_call([
+                os.path.join(args.venv, 'bin/pip'), 'freeze'
+            ], stdout=sys.stdout)
+        else:
+            with open(args.out) as out:
+                subprocess.check_call([
+                    os.path.join(args.venv, 'bin/pip'), 'freeze'
+                ], stdout=out)
 
-    subprocess.check_call([
-        os.path.join(args.venv, 'bin/pip'), 'freeze'
-    ], stdout=args.out)
+        subprocess.check_call([
+            os.path.join(args.venv, 'bin/pip'), 'freeze'
+        ], stdout=args.out)
+    finally:
+        if not args.keep_venv:
+            shutil.rmtree(args.venv)
 
 
 if __name__ == '__main__':


Test patch: