You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am developing an Ansible lookup plugin and test code for it. Both the lookup plugin and the test code for the plugin work fine.
I am using "pytest" with "pytest-ansible" for that test, and the test function uses the ansible_module fixture provided by "pytest-ansible" to invoke the builtin "set_fact" module to invoke the lookup. The test function looks like this (simplified):
import pytest
@pytest.mark.ansible(host_pattern='localhost', connection='local')
def test_mylookup(ansible_module):
expr = "lookup('myorg.mycoll.mylookup', 'someterm')" # Jinja2 expression to call the lookup to be tested
contacted = ansible_module.set_fact(result=f"{{{{ {expr} }}}}") # Call the lookup
contacted_host = contacted['localhost']
result = contacted_host['ansible_facts']['result'] # result value returned by the lookup
# ... assertions on result
Again, this all works fine. The problem is that this test does not add to the test coverage (0%). Other Python modules in my project do add to the test coverage, just the tests for Ansible plugins do not.
I suppose this is because the ansible_module object at some point uses Ansible mechanisms to execute the module, and that probably lets my lookup code run in a different thread or process. But this is speculation.
I am using the "pytest-cov" and "coverage" packages to have "pytest" count the coverage, and run the test by invoking pytest with --cov* options.
I am developing an Ansible lookup plugin and test code for it. Both the lookup plugin and the test code for the plugin work fine.
I am using "pytest" with "pytest-ansible" for that test, and the test function uses the
ansible_module
fixture provided by "pytest-ansible" to invoke the builtin "set_fact" module to invoke the lookup. The test function looks like this (simplified):Again, this all works fine. The problem is that this test does not add to the test coverage (0%). Other Python modules in my project do add to the test coverage, just the tests for Ansible plugins do not.
I suppose this is because the
ansible_module
object at some point uses Ansible mechanisms to execute the module, and that probably lets my lookup code run in a different thread or process. But this is speculation.I am using the "pytest-cov" and "coverage" packages to have "pytest" count the coverage, and run the test by invoking pytest with
--cov*
options.Relevant Python package versions (on Python 3.9):
I would like to know how I can get the test coverage properly accounted for when testing an Ansible lookup plugin with "pytest" and "pytest-ansible".
I also posted this question on SO: https://stackoverflow.com/q/79174901/1424462
The text was updated successfully, but these errors were encountered: