Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

Issue running tests when charmhelpers packages is present #18

Open
mkalcok opened this issue Oct 13, 2021 · 0 comments
Open

Issue running tests when charmhelpers packages is present #18

mkalcok opened this issue Oct 13, 2021 · 0 comments

Comments

@mkalcok
Copy link

mkalcok commented Oct 13, 2021

I noticed that when I'm running unit tests (for example for the easyrsa charm) and charmhalpers package is installed in the virtual environment, some of the mocks do not work as expected and charmhelpers actually tries to "execute".

Running tests without charmhelpers installed (passed):

$ pytest tests/
========================================================= test session starts =========================================================
platform darwin -- Python 3.9.7, pytest-6.2.5, py-1.10.0, pluggy-1.0.0
rootdir: /Users/kauchman/Work/canonical/code/charms/layer-easyrsa
plugins: cov-3.0.0
collected 25 items

tests/test_actions.py ........................                                                                                  [ 96%]
tests/test_easyrsa.py .                                                                                                         [100%]

========================================================= 25 passed in 0.34s ==========================================================

Running tests with charmhelpers installed (fail):

$ pytest tests/
========================================================= test session starts =========================================================
platform darwin -- Python 3.9.7, pytest-6.2.5, py-1.10.0, pluggy-1.0.0
rootdir: /Users/kauchman/Work/canonical/code/charms/layer-easyrsa
collected 0 items / 2 errors

=============================================================== ERRORS ================================================================
_______________________________________________ ERROR collecting tests/test_actions.py ________________________________________________
tests/test_actions.py:22: in <module>
    from actions import actions
actions/actions.py:12: in <module>
    from charms.reactive.relations import endpoint_from_name
<frozen importlib._bootstrap>:1007: in _find_and_load
    ???
<frozen importlib._bootstrap>:982: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:925: in _find_spec
    ???
../../venvs/layer-easyrsa/lib/python3.9/site-packages/charms/unit_test.py:139: in find_spec
    file_spec = self.find_real(fullname)
../../venvs/layer-easyrsa/lib/python3.9/site-packages/charms/unit_test.py:117: in find_real
    file_spec = importlib.util.find_spec(fullname)
/usr/local/Cellar/python@3.9/3.9.7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/util.py:94: in find_spec
    parent = __import__(parent_name, fromlist=['__path__'])
../../venvs/layer-easyrsa/lib/python3.9/site-packages/charms/reactive/__init__.py:22: in <module>
    from .endpoints import *  # noqa
../../venvs/layer-easyrsa/lib/python3.9/site-packages/charms/reactive/endpoints.py:23: in <module>
    from charms.reactive.helpers import data_changed
../../venvs/layer-easyrsa/lib/python3.9/site-packages/charms/reactive/helpers.py:21: in <module>
    from charmhelpers.core import host
../../venvs/layer-easyrsa/lib/python3.9/site-packages/charmhelpers/core/host.py:42: in <module>
    __platform__ = get_platform()
../../venvs/layer-easyrsa/lib/python3.9/site-packages/charmhelpers/osplatform.py:18: in get_platform
    current_platform = _get_platform_from_fs()
../../venvs/layer-easyrsa/lib/python3.9/site-packages/charmhelpers/osplatform.py:41: in _get_platform_from_fs
    with open(os.path.join(os.sep, 'etc', 'os-release')) as fin:
E   FileNotFoundError: [Errno 2] No such file or directory: '/etc/os-release'
_______________________________________________ ERROR collecting tests/test_easyrsa.py ________________________________________________
tests/test_easyrsa.py:1: in <module>
    from reactive import easyrsa
reactive/easyrsa.py:11: in <module>
    from charms.reactive.helpers import data_changed
<frozen importlib._bootstrap>:1007: in _find_and_load
    ???
<frozen importlib._bootstrap>:982: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:925: in _find_spec
    ???
../../venvs/layer-easyrsa/lib/python3.9/site-packages/charms/unit_test.py:139: in find_spec
    file_spec = self.find_real(fullname)
../../venvs/layer-easyrsa/lib/python3.9/site-packages/charms/unit_test.py:117: in find_real
    file_spec = importlib.util.find_spec(fullname)
/usr/local/Cellar/python@3.9/3.9.7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/util.py:94: in find_spec
    parent = __import__(parent_name, fromlist=['__path__'])
../../venvs/layer-easyrsa/lib/python3.9/site-packages/charms/reactive/__init__.py:22: in <module>
    from .endpoints import *  # noqa
../../venvs/layer-easyrsa/lib/python3.9/site-packages/charms/reactive/endpoints.py:23: in <module>
    from charms.reactive.helpers import data_changed
../../venvs/layer-easyrsa/lib/python3.9/site-packages/charms/reactive/helpers.py:21: in <module>
    from charmhelpers.core import host
../../venvs/layer-easyrsa/lib/python3.9/site-packages/charmhelpers/core/host.py:42: in <module>
    __platform__ = get_platform()
../../venvs/layer-easyrsa/lib/python3.9/site-packages/charmhelpers/osplatform.py:18: in get_platform
    current_platform = _get_platform_from_fs()
../../venvs/layer-easyrsa/lib/python3.9/site-packages/charmhelpers/osplatform.py:41: in _get_platform_from_fs
    with open(os.path.join(os.sep, 'etc', 'os-release')) as fin:
E   FileNotFoundError: [Errno 2] No such file or directory: '/etc/os-release'
======================================================= short test summary info =======================================================
ERROR tests/test_actions.py - FileNotFoundError: [Errno 2] No such file or directory: '/etc/os-release'
ERROR tests/test_easyrsa.py - FileNotFoundError: [Errno 2] No such file or directory: '/etc/os-release'
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 2 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
========================================================== 2 errors in 0.38s ==========================================================
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant