-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
unit test helper: big revamp #8894
unit test helper: big revamp #8894
Conversation
The CI error seems to be unrelated with the change. @felixfontein could you please confirm? TIA |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that somewhere the order of the tests comes from a dictionary. In Python 3.5 (where the tests fail) the order is 'random', while in Python 3.6+ it is insertion order. (No idea why it works in 2.7 since there it should be 'random' as well...)
I do recall something about that in 2.7 it was "random" but the seed to the random generator was kinda fixed, so the order of the keys was deterministic across multiple runs of the script. They improved that with 3.5, and I had not kept track, I did not know 3.6 onwards was using insertion order. Anyways, it is not something to rely on. |
hi @felixfontein anything else I need to adjust in this one? TIA |
- 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
- now it works not only in parametrized functions but also directly with args
- 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'
Co-authored-by: Felix Fontein <felix@fontein.de>
5cd6b5b
to
52e668c
Compare
Yup, I gave it another look. I think I know what it is: the order of the tests, in the code, is a I chose not parameterizing the test function so that fixtures could be used (with pytest.mark.usefixtures) per test function, rather than for all test cases. Anyways, whatever test code is performing this comparison between collected tests is clearly relying on the order provided by the module. I guess for the time being the only option I have is to create one single function and parameterize it. This will become a problem if developers use the test helper and create extra tests within the same test_module. Anyway I can skip Python 3.5? |
the problem lies in the pytest-xdist plugin used here: I don't want to chase the rabbit down that hole, so I will revert to a parameterized test function. |
The tests were failing on Python 3.5, as you probably noticed :) community.general 11.0.0 will drop support for Python 3.5 (though not for 2.7), and 12.0.0 will drop support for Python 2.7 as well, so at that point you can do this again :) |
Backport to stable-9: 💚 backport PR created✅ Backport PR branch: Backported as #8943 🤖 @patchback |
@russoz thanks for your contribution! |
* 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 <felix@fontein.de> * revert to parametrized test func instead of multiple funcs --------- Co-authored-by: Felix Fontein <felix@fontein.de> (cherry picked from commit 8ef77d8)
…8943) unit test helper: big revamp (#8894) * 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 <felix@fontein.de> * revert to parametrized test func instead of multiple funcs --------- Co-authored-by: Felix Fontein <felix@fontein.de> (cherry picked from commit 8ef77d8) Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
* 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 <felix@fontein.de> * revert to parametrized test func instead of multiple funcs --------- Co-authored-by: Felix Fontein <felix@fontein.de>
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
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