Verified Commit 41a4ca4c authored by Jordan Petridіs's avatar Jordan Petridіs 🌱
Browse files preserve env vars when running tests

pytest will happily run all the tests in the same proccess,
which means if one mutates an environment variable, the change
will bleed to the rest of the tests.
parent f4d6e7e9
......@@ -34,6 +34,29 @@ MANIFEST_TEMPLATE: str = """<?xml version="1.0" encoding="UTF-8"?>
# Basically, pytest will happily let a test mutate a variable, and then run
# the next tests one the same environment without reset the vars.
def preserve_ci_vars(func):
"""Preserve the original CI Variable values"""
def wrapper():
token = os.environ["CI_JOB_TOKEN"]
url = os.environ["CI_PROJECT_URL"]
user = os.environ["GITLAB_USER_LOGIN"]
except KeyError:
token = "invalid"
url = "invalid"
user = ""
os.environ["CI_JOB_TOKEN"] = token
os.environ["CI_PROJECT_URL"] = url
os.environ["GITLAB_USER_LOGIN"] = user
return wrapper
def request_raw(path: str, token: str, project_url: str) -> List[Dict[str, str]]:
gitlab_header: Dict[str, str] = {'JOB_TOKEN': token }
base_url: str = get_hostname(project_url)
......@@ -73,6 +96,7 @@ def get_project_branch(project_id: int, name: str) -> Dict[str, str]:
return request_wrap(path)
def test_get_project_branch():
id = 1353
os.environ["CI_JOB_TOKEN"] = "xxxxxxxxxxxxxxxxxxxx"
......@@ -99,6 +123,7 @@ def search_user_namespace(user: str, project: str) -> Dict[str, str]:
return request_wrap(path)
def test_search_user_namespace():
os.environ["CI_JOB_TOKEN"] = "xxxxxxxxxxxxxxxxxxxx"
os.environ["CI_PROJECT_URL"] = ""
......@@ -121,10 +146,18 @@ def search_group_namespace(group_id: str, project: str) -> Dict[str, str]:
return request_wrap(path)
def test_search_group_namespace():
import pytest
instance = get_hostname(os.environ['CI_PROJECT_URL'])
# This tests need to authenticate with the gitlab instace,
# and its hardcoded to check for the gitlab-org which exists
# on
# This can be changed to a gstreamer once its migrated to gitlab.fd.o
if instance != "":
# too lazy to use a different error
raise KeyError
except KeyError:
pytest.skip("Need to be authenticated with gitlab to succed")
......@@ -186,6 +219,7 @@ def find_repository_sha(module: str, branchname: str) -> Tuple[str, str]:
return 'origin', 'master'
def test_find_repository_sha():
os.environ["CI_JOB_TOKEN"] = "xxxxxxxxxxxxxxxxxxxx"
os.environ["CI_PROJECT_URL"] = ""
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment