Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PR #8894/8ef77d86 backport][stable-9] unit test helper: big revamp #8943

Conversation

patchback[bot]
Copy link

@patchback patchback bot commented Sep 28, 2024

This is a backport of PR #8894 as merged into main (8ef77d8).

SUMMARY

Revamped the test helper to be able to support more than just run_command(). This PR makes the code more generic and expansible, allowing for easier tests in the future.

ISSUE TYPE
  • Test Pull Request
COMPONENT NAME

tests/unit/plugins/modules/conftest.py
tests/unit/plugins/modules/helper.py
tests/unit/plugins/modules/test_cpanm.py
tests/unit/plugins/modules/test_cpanm.yaml
tests/unit/plugins/modules/test_django_check.py
tests/unit/plugins/modules/test_django_check.yaml
tests/unit/plugins/modules/test_django_check.yaml.license
tests/unit/plugins/modules/test_django_command.py
tests/unit/plugins/modules/test_django_command.yaml
tests/unit/plugins/modules/test_django_createcachetable.py
tests/unit/plugins/modules/test_django_createcachetable.yaml
tests/unit/plugins/modules/test_facter_facts.py
tests/unit/plugins/modules/test_facter_facts.yaml
tests/unit/plugins/modules/test_gconftool2.py
tests/unit/plugins/modules/test_gconftool2.yaml
tests/unit/plugins/modules/test_gconftool2_info.py
tests/unit/plugins/modules/test_gconftool2_info.yaml
tests/unit/plugins/modules/test_gio_mime.py
tests/unit/plugins/modules/test_gio_mime.yaml
tests/unit/plugins/modules/test_opkg.py
tests/unit/plugins/modules/test_opkg.yaml
tests/unit/plugins/modules/test_puppet.py
tests/unit/plugins/modules/test_puppet.yaml
tests/unit/plugins/modules/test_snap.py
tests/unit/plugins/modules/test_xfconf.py
tests/unit/plugins/modules/test_xfconf.yaml
tests/unit/plugins/modules/test_xfconf_info.py
tests/unit/plugins/modules/test_xfconf_info.yaml

* initial commit

* multiple changes:

- TestCaseContext fixture no longer need to autouse=True
- Helper.from_module() allows extra param to specify yaml file
- test_django_check: adjusted .py and .yaml

* set fixtures per testcase

* set fixtures per testcase

* rollback to original state

* patch_ansible_module fixture

- now it works not only in parametrized functions but also directly with args

* tests/unit/plugins/modules/helper.py

- improved encapsulation, class Helper no longer knows details about test cases
- test functions no longer parametrized, that allows using test case fixtures per test function
- renamed 'context' to 'mock'

* enable Helper.from_list(), better param name 'ansible_module'

* adjusted test fiels to new helper

* remove unnecessary .license file

* fix bracket

* fix reference name

* Update tests/unit/plugins/modules/helper.py

Co-authored-by: Felix Fontein <[email protected]>

* revert to parametrized test func instead of multiple funcs

---------

Co-authored-by: Felix Fontein <[email protected]>
(cherry picked from commit 8ef77d8)
@ansibullbot ansibullbot added backport new_contributor Help guide this first time contributor tests tests unit tests/unit labels Sep 28, 2024
@felixfontein felixfontein merged commit 605a557 into stable-9 Sep 28, 2024
140 checks passed
@felixfontein felixfontein deleted the patchback/backports/stable-9/8ef77d8664598154fdd51bf522c0afc62fe36b65/pr-8894 branch September 28, 2024 05:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport new_contributor Help guide this first time contributor tests tests unit tests/unit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants