Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 4 additions & 15 deletions python/avi/sdk/test/conftest.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
# Copyright 2021 VMware, Inc.
# SPDX-License-Identifier: Apache License 2.0

import json

# Module-level storage for config; set in pytest_configure when pytest runs.
# Used by test modules instead of deprecated pytest.config.getoption().
_config_file = None
_cfg = None
"""
Get the configuration from the config.yml file.
"""

def pytest_addoption(parser):
parser.addoption("--config", action="store", help="config file")

def pytest_configure(config):
"""Load --config file and store path and parsed JSON for test modules (pytest 8.x compatible)."""
global _config_file, _cfg
_config_file = config.getoption("--config", default=None)
if _config_file:
with open(_config_file) as f:
_cfg = json.load(f)
parser.addoption("--config", action="store", help="config file")
14 changes: 3 additions & 11 deletions python/avi/sdk/test/test_avi_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from avi.sdk.utils.api_utils import ApiUtils
from avi.sdk.samples.common import get_sample_ssl_params
from avi.sdk.samples.clone_vs import AviClone
from avi.sdk.test import conftest as test_conftest
from requests.packages import urllib3
from requests import Response
from multiprocessing import Pool, Process
Expand All @@ -32,16 +31,9 @@
urllib3.disable_warnings()
gapi_version = '17.2.6'

# Config is set by conftest.pytest_configure when pytest runs; fallback to load from file if needed
config_file = getattr(test_conftest, '_config_file', None)
cfg = getattr(test_conftest, '_cfg', None)
if cfg is None and config_file:
with open(config_file) as f:
cfg = json.load(f)
if cfg is None:
raise pytest.UsageError(
"Missing required --config option. Use: pytest --config=path/to/config.json ..."
)
config_file = pytest.config.getoption("--config")
with open(config_file) as f:
cfg = json.load(f)

ARG_DEFAULT_VALUE = {
'limit': 1,
Expand Down
14 changes: 3 additions & 11 deletions python/avi/sdk/test/test_saml_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,11 @@
import vcr
import unittest
from avi.sdk.saml_avi_api import ApiSession, OktaSAMLApiSession, OneloginSAMLApiSession, WS1loginSAMLApiSession
from avi.sdk.test import conftest as test_conftest

api_version = '22.1.3'
# Config is set by conftest.pytest_configure when pytest runs; fallback to load from file if needed
config_file = getattr(test_conftest, '_config_file', None)
cfg = getattr(test_conftest, '_cfg', None)
if cfg is None and config_file:
with open(config_file) as f:
cfg = json.load(f)
if cfg is None:
raise pytest.UsageError(
"Missing required --config option. Use: pytest --config=path/to/config.json ..."
)
config_file = pytest.config.getoption("--config")
with open(config_file) as f:
cfg = json.load(f)

my_vcr = vcr.VCR(
cassette_library_dir='python/avi/sdk/test/fixtures/saml_cassettes/',
Expand Down