Closed cjw296 closed 4 years ago
_AwaitEvent
and mock.awaited
were removed in https://github.com/python/cpython/pull/16443 . So I guess it can be removed here too.AsyncMock
in https://github.com/python/cpython/pull/17906.unittest.async_case
which increases the backporting effort needed :(Questions :
Thank you very much Chris for this effort :)
I've started from the revision in https://github.com/testing-cabal/mock/pull/476/commits/ce5b6961d0b38b9f26e6bffabf46fadfc55696ba, it's also stored in lastsync.txt in the repo (the backporting instructions in the docs and backport.py
give the full details).
The reason for this is that it's the revision before the problematic positional-only argument commit. As we discussed by email, my plan is to skip that patch and the use backport.py
to bring the repo up to cpython's current master
before doing a 4.0 release. So, all the changes you mention will get pulled in, along with their problems and challenges :-/
Only DeprecationWarnings are hidden: https://github.com/testing-cabal/mock/blob/master/setup.cfg#L54 - so all others should be visible in the test run output.
I'd suggest waiting until I've got up to current cpython master
before really looking at this, if I hit issues before then I'll ping you on this issue for help :-)
Thanks for the details. Sure, I will be happy to help :)
It's interesting to see what's missing coverage:
https://app.circleci.com/jobs/github/testing-cabal/mock/4555
I wish we could introduce coverage gating upstream, especially for a library like mock
, there's no excuse for having lines of code that aren't covered by tests.
@lisroach - can you talk me through the change in https://github.com/python/cpython/commit/f1a297acb60b88917712450ebd3cfa707e6efd6b as it causes the following failure on Py3.6 when backported:
______________________________________ SpecSignatureTest.test_autospec_on_bound_builtin_function _______________________________________
self = <mock.tests.testhelpers.SpecSignatureTest testMethod=test_autospec_on_bound_builtin_function>
@pytest.mark.skipif(IS_PYPY,
reason="https://bitbucket.org/pypy/pypy/issues/3010")
def test_autospec_on_bound_builtin_function(self):
meth = types.MethodType(time.ctime, time.time())
self.assertIsInstance(meth(), str)
> mocked = create_autospec(meth)
mock/tests/testhelpers.py:899:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
mock/mock.py:2603: in create_autospec
name=_name, **_kwargs)
mock/mock.py:416: in __new__
if _is_async_obj(bound_args[spec_arg[0]]):
mock/mock.py:52: in _is_async_obj
return asyncio.iscoroutinefunction(obj) or inspect.isawaitable(obj)
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/coroutines.py:256: in iscoroutinefunction
_inspect_iscoroutinefunction(func))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
object = <bound method ctime of 1579078759.885324>
def iscoroutinefunction(object):
"""Return true if the object is a coroutine function.
Coroutine functions are defined with "async def" syntax.
"""
return bool((isfunction(object) or ismethod(object)) and
> object.__code__.co_flags & CO_COROUTINE)
E AttributeError: 'builtin_function_or_method' object has no attribute '__code__'
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/inspect.py:185: AttributeError
My upstream PR helps with code coverage for AsyncMock
https://github.com/python/cpython/pull/17906 .. IIRC you have pruned some untested code to get to 100% coverage earlier.
@cjw296 thanks for doing all of this work!
I think that test failure is because the inspect.iscoroutinefunction
was fixed between 3.6 and 3.8, in 3.8 it actually checks there is a __code__
before doing the call (https://github.com/python/cpython/commit/fcef60f59d04c63b3540b4c4886226098c1bacd1) to prevent crashing. I made that change in my commit because I found not all Awaitables have a __code__
attribute, making the check invalid in those cases.
We can update upstream to be backwards compatible here, maybe we need to pull in the _has_code_flag
function from 3.8's inspect
module into mock? That's not very elegant but I'm trying to think of another way around it.
@lisroach - Yeah, for now I've backported the stuff from Python 3.8 in 0c4ceaa. It's bigger than I'd like and maybe we can find a different way once I catch this branch up to cpython master.
Hmm, is the call.count()
error due to removal of the overridden definition in https://github.com/testing-cabal/mock/pull/476/commits/fadfea9d6325024e904cbbbfd9906da98b38a43f#diff-82bfc8fa2208ad81d6c698a452a77c2aL2560 ? I am wondering why it's not an error in CPython test suite.
Yeah, going to dig into it now. My only guess is that I screwed up a backport, or the need for these went away sometime after 3.8...
Yep, screwed up backporting on 72c359912d36705a94fca8b63d80451905a14ae4 / GH-15565 so redoing.
@lisroach - anything you can suggest to get these 6 failing AsyncMock tests passing on Python 3.6?
https://app.circleci.com/jobs/github/testing-cabal/mock/4513