mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
[PR #8387/da2c87ce backport][stable-9] fix test helper handling of rc (#8414)
fix test helper handling of rc (#8387)
* fix test helper handling of rc
* fix side_effect logic for rc != 0
* fix side_effect func + sanity tests
* fix ignore files
* fix code
* revamp the generator for run_command calls returns in testcase
* remove unused import
* Update tests/sanity/ignore-2.18.txt
Co-authored-by: Felix Fontein <felix@fontein.de>
* Update tests/sanity/ignore-2.17.txt
Co-authored-by: Felix Fontein <felix@fontein.de>
---------
Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit da2c87ce0d
)
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
This commit is contained in:
parent
23af148021
commit
802f8ea224
4 changed files with 16 additions and 8 deletions
|
@ -11,4 +11,5 @@ plugins/modules/udm_user.py import-3.12 # Uses deprecated stdlib library 'crypt
|
||||||
plugins/modules/xfconf.py validate-modules:return-syntax-error
|
plugins/modules/xfconf.py validate-modules:return-syntax-error
|
||||||
plugins/module_utils/univention_umc.py pylint:use-yield-from # suggested construct does not work with Python 2
|
plugins/module_utils/univention_umc.py pylint:use-yield-from # suggested construct does not work with Python 2
|
||||||
tests/unit/compat/mock.py pylint:use-yield-from # suggested construct does not work with Python 2
|
tests/unit/compat/mock.py pylint:use-yield-from # suggested construct does not work with Python 2
|
||||||
|
tests/unit/plugins/modules/helper.py pylint:use-yield-from # suggested construct does not work with Python 2
|
||||||
tests/unit/plugins/modules/test_gio_mime.yaml no-smart-quotes
|
tests/unit/plugins/modules/test_gio_mime.yaml no-smart-quotes
|
||||||
|
|
|
@ -11,4 +11,5 @@ plugins/modules/udm_user.py import-3.12 # Uses deprecated stdlib library 'crypt
|
||||||
plugins/modules/xfconf.py validate-modules:return-syntax-error
|
plugins/modules/xfconf.py validate-modules:return-syntax-error
|
||||||
plugins/module_utils/univention_umc.py pylint:use-yield-from # suggested construct does not work with Python 2
|
plugins/module_utils/univention_umc.py pylint:use-yield-from # suggested construct does not work with Python 2
|
||||||
tests/unit/compat/mock.py pylint:use-yield-from # suggested construct does not work with Python 2
|
tests/unit/compat/mock.py pylint:use-yield-from # suggested construct does not work with Python 2
|
||||||
|
tests/unit/plugins/modules/helper.py pylint:use-yield-from # suggested construct does not work with Python 2
|
||||||
tests/unit/plugins/modules/test_gio_mime.yaml no-smart-quotes
|
tests/unit/plugins/modules/test_gio_mime.yaml no-smart-quotes
|
||||||
|
|
|
@ -9,7 +9,6 @@ __metaclass__ = type
|
||||||
import sys
|
import sys
|
||||||
import json
|
import json
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from itertools import chain, repeat
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import yaml
|
import yaml
|
||||||
|
@ -76,12 +75,21 @@ class _RunCmdContext(_BaseContext):
|
||||||
self.mock_run_cmd = self._make_mock_run_cmd()
|
self.mock_run_cmd = self._make_mock_run_cmd()
|
||||||
|
|
||||||
def _make_mock_run_cmd(self):
|
def _make_mock_run_cmd(self):
|
||||||
call_results = [(x.rc, x.out, x.err) for x in self.run_cmd_calls]
|
def _results():
|
||||||
error_call_results = (123,
|
for result in [(x.rc, x.out, x.err) for x in self.run_cmd_calls]:
|
||||||
"OUT: testcase has not enough run_command calls",
|
yield result
|
||||||
"ERR: testcase has not enough run_command calls")
|
raise Exception("testcase has not enough run_command calls")
|
||||||
|
|
||||||
|
results = _results()
|
||||||
|
|
||||||
|
def side_effect(self_, **kwargs):
|
||||||
|
result = next(results)
|
||||||
|
if kwargs.get("check_rc", False) and result[0] != 0:
|
||||||
|
raise Exception("rc = {0}".format(result[0]))
|
||||||
|
return result
|
||||||
|
|
||||||
mock_run_command = self.mocker.patch('ansible.module_utils.basic.AnsibleModule.run_command',
|
mock_run_command = self.mocker.patch('ansible.module_utils.basic.AnsibleModule.run_command',
|
||||||
side_effect=chain(call_results, repeat(error_call_results)))
|
side_effect=side_effect)
|
||||||
return mock_run_command
|
return mock_run_command
|
||||||
|
|
||||||
def check_results(self, results):
|
def check_results(self, results):
|
||||||
|
|
|
@ -30,8 +30,6 @@
|
||||||
settings: whatever.settings
|
settings: whatever.settings
|
||||||
output:
|
output:
|
||||||
failed: true
|
failed: true
|
||||||
flags:
|
|
||||||
xfail: not seem to be failing as it should
|
|
||||||
run_command_calls:
|
run_command_calls:
|
||||||
- command: [/testbin/python, -m, django, check, --no-color, --settings=whatever.settings, babaloo, yaba, daba, doo]
|
- command: [/testbin/python, -m, django, check, --no-color, --settings=whatever.settings, babaloo, yaba, daba, doo]
|
||||||
environ: *env-def
|
environ: *env-def
|
||||||
|
|
Loading…
Reference in a new issue