|
|
@ -3,12 +3,23 @@ from __future__ import (absolute_import, division, print_function)
|
|
|
|
__metaclass__ = type
|
|
|
|
__metaclass__ = type
|
|
|
|
|
|
|
|
|
|
|
|
import os
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# set by ansible-test to a single directory, rather than a list of directories as supported by Ansible itself
|
|
|
|
# set by ansible-test to a single directory, rather than a list of directories as supported by Ansible itself
|
|
|
|
ANSIBLE_COLLECTIONS_PATH = os.path.join(os.environ['ANSIBLE_COLLECTIONS_PATH'], 'ansible_collections')
|
|
|
|
ANSIBLE_COLLECTIONS_PATH = os.path.join(os.environ['ANSIBLE_COLLECTIONS_PATH'], 'ansible_collections')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# this monkeypatch to _pytest.pathlib.resolve_package_path fixes PEP420 resolution for collections in pytest >= 6.0.0
|
|
|
|
|
|
|
|
# NB: this code should never run under py2
|
|
|
|
|
|
|
|
def collection_resolve_package_path(path):
|
|
|
|
|
|
|
|
"""Configure the Python package path so that pytest can find our collections."""
|
|
|
|
|
|
|
|
for parent in path.parents:
|
|
|
|
|
|
|
|
if str(parent) == ANSIBLE_COLLECTIONS_PATH:
|
|
|
|
|
|
|
|
return parent
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
raise Exception('File "%s" not found in collection path "%s".' % (path, ANSIBLE_COLLECTIONS_PATH))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# this monkeypatch to py.path.local.LocalPath.pypkgpath fixes PEP420 resolution for collections in pytest < 6.0.0
|
|
|
|
def collection_pypkgpath(self):
|
|
|
|
def collection_pypkgpath(self):
|
|
|
|
"""Configure the Python package path so that pytest can find our collections."""
|
|
|
|
"""Configure the Python package path so that pytest can find our collections."""
|
|
|
|
for parent in self.parts(reverse=True):
|
|
|
|
for parent in self.parts(reverse=True):
|
|
|
@ -26,12 +37,24 @@ def pytest_configure():
|
|
|
|
except AttributeError:
|
|
|
|
except AttributeError:
|
|
|
|
pytest_configure.executed = True
|
|
|
|
pytest_configure.executed = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# noinspection PyProtectedMember
|
|
|
|
from ansible.utils.collection_loader._collection_finder import _AnsibleCollectionFinder
|
|
|
|
from ansible.utils.collection_loader._collection_finder import _AnsibleCollectionFinder
|
|
|
|
|
|
|
|
|
|
|
|
# allow unit tests to import code from collections
|
|
|
|
# allow unit tests to import code from collections
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# noinspection PyProtectedMember
|
|
|
|
_AnsibleCollectionFinder(paths=[os.path.dirname(ANSIBLE_COLLECTIONS_PATH)])._install() # pylint: disable=protected-access
|
|
|
|
_AnsibleCollectionFinder(paths=[os.path.dirname(ANSIBLE_COLLECTIONS_PATH)])._install() # pylint: disable=protected-access
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
# noinspection PyProtectedMember
|
|
|
|
|
|
|
|
from _pytest import pathlib as _pytest_pathlib
|
|
|
|
|
|
|
|
except ImportError:
|
|
|
|
|
|
|
|
_pytest_pathlib = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if hasattr(_pytest_pathlib, 'resolve_package_path'):
|
|
|
|
|
|
|
|
_pytest_pathlib.resolve_package_path = collection_resolve_package_path
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
# looks like pytest <= 6.0.0, use the old hack against py.path
|
|
|
|
# noinspection PyProtectedMember
|
|
|
|
# noinspection PyProtectedMember
|
|
|
|
import py._path.local
|
|
|
|
import py._path.local
|
|
|
|
|
|
|
|
|
|
|
|