mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Add pytest.skip_if_container()
Reviewed-By: Christian Heimes <cheimes@redhat.com>
This commit is contained in:
parent
c5c52bfe3f
commit
a009b9e034
@ -71,7 +71,7 @@ def _parse_osrelease(filename='/etc/os-release'):
|
||||
|
||||
|
||||
class OSInfo(Mapping):
|
||||
__slots__ = ('_info', '_platform')
|
||||
__slots__ = ('_info', '_platform', '_container')
|
||||
|
||||
bsd_family = (
|
||||
'freebsd',
|
||||
@ -95,6 +95,7 @@ class OSInfo(Mapping):
|
||||
raise ValueError("Unsupported platform: {}".format(sys.platform))
|
||||
self._info = info
|
||||
self._platform = None
|
||||
self._container = None
|
||||
|
||||
def _handle_linux(self):
|
||||
"""Detect Linux distribution from /etc/os-release
|
||||
@ -208,6 +209,17 @@ class OSInfo(Mapping):
|
||||
raise ImportError('No ipaplatform available for "{}"'.format(
|
||||
', '.join(self.platform_ids)))
|
||||
|
||||
@property
|
||||
def container(self):
|
||||
if self._container is not None:
|
||||
return self._container
|
||||
from ipaplatform.tasks import tasks
|
||||
try:
|
||||
self._container = tasks.detect_container()
|
||||
except NotImplementedError:
|
||||
raise NotImplementedError(
|
||||
'Platform does not support detecting containers')
|
||||
return self._container
|
||||
|
||||
osinfo = OSInfo()
|
||||
ipaplatform.NAME = osinfo.platform
|
||||
|
@ -47,6 +47,8 @@ MARKERS = [
|
||||
'needs_ipaapi: Test needs IPA API',
|
||||
('skip_if_platform(platform, reason): Skip test on platform '
|
||||
'(ID and ID_LIKE)'),
|
||||
('skip_if_container(type, reason): Skip test on container '
|
||||
'("any" or specific type)'),
|
||||
]
|
||||
|
||||
|
||||
@ -158,6 +160,15 @@ def pytest_runtest_setup(item):
|
||||
reason = mark.kwargs["reason"]
|
||||
if platform in osinfo.platform_ids:
|
||||
pytest.skip(f"Skip test on platform {platform}: {reason}")
|
||||
for mark in item.iter_markers(name="skip_if_container"):
|
||||
container = mark.kwargs.get("container")
|
||||
if container is None:
|
||||
container = mark.args[0]
|
||||
reason = mark.kwargs["reason"]
|
||||
if osinfo.container is not None:
|
||||
if container in ('any', osinfo.container):
|
||||
pytest.skip(
|
||||
f"Skip test on '{container}' container type: {reason}")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
Loading…
Reference in New Issue
Block a user