forked from Azure/azure-sdk-for-python
-
Notifications
You must be signed in to change notification settings - Fork 1
/
conftest.py
59 lines (49 loc) · 2.03 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
import os
import sys
import pytest
from azure.identity._constants import EnvironmentVariables
# IMDS tests must be run explicitly
collect_ignore_glob = ["*imds*"] # pylint:disable=invalid-name
# Ignore collection of async tests on unsupported platforms
if sys.version_info < (3, 5):
collect_ignore_glob.append("*_async.py")
@pytest.fixture()
def live_identity_settings(): # pylint:disable=inconsistent-return-statements
"""Fixture for live Identity tests. Skips them when environment configuration is incomplete."""
missing_variables = [
v
for v in (
EnvironmentVariables.AZURE_CLIENT_ID,
EnvironmentVariables.AZURE_CLIENT_SECRET,
EnvironmentVariables.AZURE_TENANT_ID,
)
if not os.environ.get(v)
]
if any(missing_variables):
pytest.skip("Environment has no value for {}".format(missing_variables))
else:
return {
"client_id": os.environ[EnvironmentVariables.AZURE_CLIENT_ID],
"client_secret": os.environ[EnvironmentVariables.AZURE_CLIENT_SECRET],
"tenant_id": os.environ[EnvironmentVariables.AZURE_TENANT_ID],
}
@pytest.fixture()
def live_certificate_settings(live_identity_settings): # pylint:disable=inconsistent-return-statements,redefined-outer-name
"""Fixture for live tests needing a certificate.
Skips them when environment configuration is incomplete.
"""
pem_content = os.environ.get("PEM_CONTENT")
if not pem_content:
pytest.skip("Environment has no value for 'PEM_CONTENT'")
return
pem_path = os.path.join(os.path.dirname(__file__), "certificate.pem")
try:
with open(pem_path, "w") as pem_file:
pem_file.write(pem_content)
return dict(live_identity_settings, cert_path=pem_path)
except IOError as ex:
pytest.skip("Failed to write file '{}': {}".format(pem_path, ex))