Module: check_mk
Branch: master
Commit: 6a23e84a949fab117fea1e141fb7c39122cb3678
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=6a23e84a949fab…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Fri May 25 12:10:49 2018 +0200
Use pipenv to determine virtual environment.
Change-Id: Ic07fb490eb2dd3ae2a07e35e20940a6633b6bd85
---
tests/conftest.py | 6 +-----
tests/testlib/__init__.py | 21 +++++++++++++++------
2 files changed, 16 insertions(+), 11 deletions(-)
diff --git a/tests/conftest.py b/tests/conftest.py
index 19a880b..c786c33 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -166,15 +166,11 @@ def pytest_cmdline_main(config):
def verify_virtualenv():
- if not is_running_in_virtualenv():
+ if not virtualenv_path():
raise SystemExit("ERROR: Please load virtual environment first "
"(Use \"pipenv shell\" or configure
direnv)")
-def is_running_in_virtualenv():
- return os.environ.get("PIP_PYTHON_PATH")
-
-
def is_running_as_site_user():
return pwd.getpwuid(os.getuid()).pw_name == _site_id()
diff --git a/tests/testlib/__init__.py b/tests/testlib/__init__.py
index 01097d1..2a19766 100644
--- a/tests/testlib/__init__.py
+++ b/tests/testlib/__init__.py
@@ -9,6 +9,7 @@ import platform
import re
import requests
import socket
+import pathlib2 as pathlib
import pipes
import subprocess
import sys
@@ -54,6 +55,14 @@ def var_dir():
return base_dir
+def virtualenv_path():
+ try:
+ venv = subprocess.check_output(["pipenv", "--bare",
"--venv"])
+ return pathlib2.Path(venv.decode("utf-8").rstrip("\n"))
+ except subprocess.CalledProcessError:
+ return None
+
+
class APIError(Exception):
pass
@@ -650,20 +659,20 @@ class Site(object):
def _install_test_python_modules(self):
- python_home = os.environ.get("VIRTUAL_ENV")
- bin_dir = os.path.join(python_home, "bin")
- packages_dir = os.path.join(python_home,
"lib/python2.7/site-packages")
+ venv = virtualenv_path()
+ bin_dir = venv / "bin"
+ packages_dir = venv / "lib/python2.7/site-packages"
- for file_name in os.listdir(packages_dir):
+ for file_name in os.listdir(str(packages_dir)):
#if "cffi" in file_name:
# continue
assert os.system("sudo rsync -a --chown %s:%s %s
%s/local/lib/python/" %
- (self.id, self.id, os.path.join(packages_dir, file_name),
self.root)) >> 8 == 0
+ (self.id, self.id, packages_dir / file_name, self.root)) >> 8
== 0
for file_name in [ "py.test", "pytest" ]:
assert os.system("sudo rsync -a --chown %s:%s %s %s/local/bin" %
- (self.id, self.id, os.path.join(bin_dir, file_name), self.root))
>> 8 == 0
+ (self.id, self.id, bin_dir / file_name, self.root)) >> 8 == 0
def rm_if_not_reusing(self):