ansible/pytest-ansible

ModuleNotFoundError when a function being tested is importing from another module

vncntk opened this issue · 1 comments

Here is how the directories are structured.

playbooks/
    module_utils/
        __init__.py
        my_custom_module.py
        my_other_custom_module_util .py
tests/
    __init__.py
    test_module_utils/
        test_my_custom_module.py

And in my_custom_module.py it is importing from another file in module_utils likeso:

from ansible.module_utils.my_other_custom_module_util import some_func

When running pytest it returns an error
ModuleNotFoundError: No module named 'ansible.module_utils.my_other_custom_module_util'

Any ideas how to fix this?

hey, are you using virtual environment?
If yes try switching it to a new one and installing the required dependencies again, that may solve the issue!