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

Tests fail with 1.11.2 #169

Closed
chbndrhnns opened this issue Nov 19, 2019 · 5 comments · Fixed by #170 or #171
Closed

Tests fail with 1.11.2 #169

chbndrhnns opened this issue Nov 19, 2019 · 5 comments · Fixed by #170 or #171

Comments

@chbndrhnns
Copy link

chbndrhnns commented Nov 19, 2019

After upgrading to 1.11.2, my tests using pytest-mock start failing with the message below. It turns out this change fixes it but it still needs to be released.

I am using pytest 5.2.4

self = <pytest_mock.plugin.MockFixture._Patcher object at 0x104e8c590>
stack = [FrameInfo(frame=<frame at 0x104cfc5c0, file '/Users/powerjo/.local/share/virtualenvs/backend-qQJPOvQO/lib/python3.7/s...92, function='_hookexec', code_context=['        return self._inner_hookexec(hook, methods, kwargs)\n'], index=0), ...]

    def _enforce_no_with_context(self, stack):
        """raises a ValueError if mocker is used in a with context"""
        caller = stack[1]
        frame = caller[0]
        info = inspect.getframeinfo(frame)
>       code_context = " ".join(info.code_context).strip()
E       TypeError: can only join an iterable

../../../../.local/share/virtualenvs/backend-qQJPOvQO/lib/python3.7/site-packages/pytest_mock/plugin.py:167: TypeError
@nicoddemus
Copy link
Member

Hi @chbndrhnns, thanks for the nudge! 1.12 released. 👍

@richin13
Copy link

richin13 commented Nov 19, 2019

Hi @nicoddemus: I'm currently receiving this error as well. Here's the relevant part of my poetry show command

pytest                  5.2.4   pytest: simple powerful testing with Python
pytest-clarity          0.2.0a1 A plugin providing an alternative, colourful diff output for failing assertions.
pytest-cov              2.8.1   Pytest plugin for measuring coverage.
pytest-flask-sqlalchemy 1.0.2   A pytest plugin for preserving test isolation in Flask-SQlAlchemy using database transactions.
pytest-mock             1.12.0  Thin-wrapper around the mock package for easier use with py.test

Any ideas? 😢

@nicoddemus
Copy link
Member

Hi @richin13,

Sorry to hear!

I think info.code_context might be None:

>>> " ".join(None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: can only join an iterable

Hmmm any chance you don't have the source code of the place where the code is used?

If I compile some code to a .pyc file, remove the original source, then execute the .pyc, I get code_context also equal to None:

λ py -3 foo.cpython-38.pyc
Traceback(filename='foo.py', lineno=15, function='main', code_context=None, index=None)

@richin13
Copy link

richin13 commented Nov 20, 2019

Thank you so much @nicoddemus: turns out I forgot to clean my __pycache__ and related files. Removing them fixed the issue. Thanks again

nicoddemus added a commit to nicoddemus/pytest-mock that referenced this issue Nov 20, 2019
nicoddemus added a commit to nicoddemus/pytest-mock that referenced this issue Nov 20, 2019
nicoddemus added a commit to nicoddemus/pytest-mock that referenced this issue Nov 20, 2019
@nicoddemus
Copy link
Member

@richin13 thanks for confirming it. I just released 1.12.1 with a fix for this problem. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants