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

test: minor tests fix to run tests without tox #1327

Closed
wants to merge 1 commit into from

Conversation

dimaqq
Copy link
Contributor

@dimaqq dimaqq commented Aug 22, 2024

Below is the failure when running the tests in a venv (without Tox). This PR fixes that.

(.ahh-venv) dima@colima-ahh /c/operator (main)> pytest --ignore=test/smoke -vx -k test_exec
==================================================== test session starts =====================================================
platform linux -- Python 3.12.3, pytest-7.4.4, pluggy-1.5.0 -- /code/operator/.ahh-venv/bin/python
cachedir: .pytest_cache
rootdir: /code/operator
collected 1190 items / 1176 deselected / 14 selected

test/test_model.py::TestContainerPebble::test_exec FAILED                                                              [  7%]

========================================================== FAILURES ==========================================================
_______________________________________________ TestContainerPebble.test_exec ________________________________________________

args = (<test.test_model.TestContainerPebble object at 0xe48b8f41ab70>,)
keywargs = {'container': <ops.model.Container object at 0xe48b8f076270>}

    @wraps(func)
    def patched(*args, **keywargs):
>       with self.decoration_helper(patched,
                                    args,
                                    keywargs) as (newargs, newkeywargs):

/usr/lib/python3.12/unittest/mock.py:1387:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/usr/lib/python3.12/contextlib.py:137: in __enter__
    return next(self.gen)
/usr/lib/python3.12/unittest/mock.py:1369: in decoration_helper
    arg = exit_stack.enter_context(patching)
/usr/lib/python3.12/contextlib.py:526: in enter_context
    result = _enter(cm)
/usr/lib/python3.12/unittest/mock.py:1442: in __enter__
    self.target = self.getter()
/usr/lib/python3.12/pkgutil.py:513: in resolve_name
    mod = importlib.import_module(modname)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

name = 'model', package = None

    def import_module(name, package=None):
        """Import a module.

        The 'package' argument is required when performing a relative import. It
        specifies the package to use as the anchor point from which to resolve the
        relative import to an absolute import.

        """
        level = 0
        if name.startswith('.'):
            if not package:
                raise TypeError("the 'package' argument is required to perform a "
                                f"relative import for {name!r}")
            for character in name:
                if character != '.':
                    break
                level += 1
>       return _bootstrap._gcd_import(name[level:], package, level)
E       ModuleNotFoundError: No module named 'model'

/usr/lib/python3.12/importlib/__init__.py:90: ModuleNotFoundError
================================================== short test summary info ===================================================
FAILED test/test_model.py::TestContainerPebble::test_exec - ModuleNotFoundError: No module named 'model'
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
============================================= 1 failed, 1176 deselected in 0.26s =============================================

@dimaqq dimaqq changed the title fix: minor tests fix to run tests without tox tests: minor tests fix to run tests without tox Aug 22, 2024
@dimaqq dimaqq changed the title tests: minor tests fix to run tests without tox test: minor tests fix to run tests without tox Aug 22, 2024
Copy link
Collaborator

@benhoyt benhoyt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see the message in Ops Library Development now -- I've updated the PR description to include it directly.

I don't see any reason not to do this -- thanks!

@dimaqq
Copy link
Contributor Author

dimaqq commented Aug 23, 2024

The fix is no longer needed after #1313

@dimaqq dimaqq closed this Aug 23, 2024
@dimaqq dimaqq deleted the fix-tests-outside-tox branch August 23, 2024 05:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants