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

AttributeError: module 'unittest.mock' has no attribute '_is_started' #149

Open
rndusr opened this issue May 2, 2020 · 4 comments
Open

Comments

@rndusr
Copy link
Contributor

rndusr commented May 2, 2020

This happens with Python 3.8.3rc1.

I don't know how to reproduce this issue but it looks like asynctest is using a private function that is commented as "XXXX horrible" that was removed in this commit: python/cpython@4b222c9

@Martiusweb
Copy link
Owner

Can you provide a stack trace?

@rndusr
Copy link
Contributor Author

rndusr commented May 2, 2020

Sure thing.

self = <[AttributeError("'_PatchedGenerator' object has no attribute 'generator'") raised in repr()] _PatchedGenerator object at 0x7f034d1a1490>

    def __next__(self):
        try:
            with self._limited_patchings_stack():
>               return self.gen.send(None)
E               StopIteration

venv/lib/python3.8/site-packages/asynctest/mock.py:1041: StopIteration

During handling of the above exception, another exception occurred:
venv/lib/python3.8/site-packages/asynctest/case.py:297: in run
    self._run_test_method(testMethod)
venv/lib/python3.8/site-packages/asynctest/case.py:354: in _run_test_method
    self.loop.run_until_complete(result)
venv/lib/python3.8/site-packages/asynctest/case.py:224: in wrapper
    return method(*args, **kwargs)
/usr/lib/python3.8/asyncio/base_events.py:616: in run_until_complete
    return future.result()
venv/lib/python3.8/site-packages/asynctest/mock.py:115: in wrapper
    return await coroutine(*args, **kwargs)
venv/lib/python3.8/site-packages/asynctest/mock.py:1044: in __next__
    self._stop_global_patchings()
venv/lib/python3.8/site-packages/asynctest/mock.py:1032: in _stop_global_patchings
    if _is_started(patching):
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

patching = <asynctest.mock._patch object at 0x7f034d2c60a0>

    def _is_started(patching):
        if isinstance(patching, _patch_dict):
            return patching._is_started
        else:
>           return unittest.mock._is_started(patching)
E           AttributeError: module 'unittest.mock' has no attribute '_is_started'

venv/lib/python3.8/site-packages/asynctest/mock.py:124: AttributeError

@gsauthof
Copy link

gsauthof commented Jun 8, 2020

I can confirm this issue on Python 3.9.

When running the unittests there are multiple instances of this error - e.g.:

test_generator_arg_is_default_mock (test.Test_patch_decorator_coroutine_or_generator) ... ERROR
Exception ignored in: <function _PatchedGenerator.__del__ at 0xf6b8c9b8>
Traceback (most recent call last):
  File "/builddir/build/BUILD/asynctest-0.13.0/asynctest/mock.py", line 1065, in __del__
    self._stop_global_patchings()
  File "/builddir/build/BUILD/asynctest-0.13.0/asynctest/mock.py", line 1032, in _stop_global_patchings
    if _is_started(patching):
  File "/builddir/build/BUILD/asynctest-0.13.0/asynctest/mock.py", line 124, in _is_started
    return unittest.mock._is_started(patching)

See https://kojipkgs.fedoraproject.org//work/tasks/8916/45078916/build.log for details.

This log also contains a bunch of other errors.

@thehesiod
Copy link

btw work-around is switching unittest.IsolatedAsyncioTestCase

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

No branches or pull requests

4 participants