asynctest
asynctest copied to clipboard
Bugfix/126 coroutine deprecated warnings
Addresses 126 Addresses 132
This change removes the usages of @asyncio.coroutine
and replaces them with the recommended async def
functions instead. This is because as of Python3.8 which is now in Beta at the time of writing, using @asyncio.coroutine
results in a deprecation warning.
This leaves two errors currently, both of which I am struggling to track down the source of, as they appear to have occurred when the file was loaded. One of which already existed from where I forked from.
$ python -m unittest --locals
EE
======================================================================
Traceback (most recent call last):
File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/usr/lib/python3.7/unittest/__main__.py", line 18, in <module>
main(module=None)
File "/usr/lib/python3.7/unittest/main.py", line 101, in __init__
self.runTests()
File "/usr/lib/python3.7/unittest/main.py", line 271, in runTests
self.result = testRunner.run(self.test)
File "/usr/lib/python3.7/unittest/runner.py", line 183, in run
result.printErrors()
File "/usr/lib/python3.7/unittest/runner.py", line 109, in printErrors
self.printErrorList('ERROR', self.errors)
File "/usr/lib/python3.7/unittest/runner.py", line 115, in printErrorList
self.stream.writeln("%s: %s" % (flavour,self.getDescription(test)))
File "/usr/lib/python3.7/unittest/runner.py", line 47, in getDescription
return '\n'.join((str(test), doc_first_line))
File "/usr/lib/python3.7/unittest/case.py", line 1400, in __str__
self._testFunc.__name__)
AttributeError: 'str' object has no attribute '__name__'
$ _
if you have any ideas on what is causing these, I will be happy to address them in this PR if desired.
Thanks
N.K.
Also, somewhat interestingly, the errors you are getting on your AppVeyor CI did not occur for me on Python3.7.
Build started
git clone -q https://github.com/Martiusweb/asynctest.git C:\projects\asynctest
git fetch -q origin +refs/pull/134/merge:
git checkout -qf FETCH_HEAD
Running Install scripts
%PYTHON%\python.exe -m pip install --upgrade pip
Collecting pip
Downloading https://files.pythonhosted.org/packages/5c/e0/be401c003291b56efc55aeba6a80ab790d3d4cece2778288d65323009420/pip-19.1.1-py2.py3-none-any.whl (1.4MB)
Installing collected packages: pip
Found existing installation: pip 18.1
Uninstalling pip-18.1:
Successfully uninstalled pip-18.1
Successfully installed pip-19.1.1
%PYTHON%\python.exe -m pip install --upgrade wheel>=0.30.0 setuptools>=36.6.0
WARNING: The script wheel.exe is installed in 'C:\Python37-x64\Scripts' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
%PYTHON%\python.exe -m unittest test
Traceback (most recent call last):
File "C:\Python37-x64\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "C:\Python37-x64\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Python37-x64\lib\unittest\__main__.py", line 18, in <module>
main(module=None)
File "C:\Python37-x64\lib\unittest\main.py", line 100, in __init__
self.parseArgs(argv)
File "C:\Python37-x64\lib\unittest\main.py", line 147, in parseArgs
self.createTests()
File "C:\Python37-x64\lib\unittest\main.py", line 159, in createTests
self.module)
File "C:\Python37-x64\lib\unittest\loader.py", line 220, in loadTestsFromNames
suites = [self.loadTestsFromName(name, module) for name in names]
File "C:\Python37-x64\lib\unittest\loader.py", line 220, in <listcomp>
suites = [self.loadTestsFromName(name, module) for name in names]
File "C:\Python37-x64\lib\unittest\loader.py", line 154, in loadTestsFromName
module = __import__(module_name)
File "C:\projects\asynctest\test\__init__.py", line 3, in <module>
from .test_mock import *
File "C:\projects\asynctest\test\test_mock.py", line 500, in <module>
_Test_Spec_Spec_Set_Returns_Coroutine_Mock):
TypeError: Cannot create a consistent method resolution
order (MRO) for bases TestCase, _Test_called_coroutine, _Test_Spec_Spec_Set_Returns_Coroutine_Mock
Command exited with code 1
(for reference).
Not quite sure what is going on here.
Hi,
Thank you for the PR.
The first error est related to the way tests must be called:
python -m unittest test/
The test/
is required, and in fact I don't really remember why it doesn't work when just calling python -m unittest
(this has to do with the way patches are tested, I think).
If you run the tests this way you will have the same error as the one you see in the CI. Unfortunately, this shows that deprecating asyncio.coroutine
in asynctest is unfortunately more complex. In many places, old and new style coroutines are handled as different types of objects and are tested separately (this is probably why there's a conflict when running the tests).
This means that in order to stop using old-style coroutines, first, we need to be sure that we can drop the support of Python 3.4 (since it reached EOL, it's probably OK). Then, we need to remove all the code which treats old-style and new style coroutines differently (especially in tests) and ensures it works will all other current versions of Python.
On a side node, there are a lot of changes required to make asynctest is compatible with Python 3.8. Until I figure out how to deal with Python 3.8, I don't think that it's worth spending to much time on this issue, since asynctest can't be used with the version that shows these deprecation messages anyway.
@Martiusweb, any updates on this? As Python 3.8 is becoming the default in distros (e.g. Debian), these issues become serious.
See e.g. #954554
cc #132, #126
As I just commented in the other bug, maybe this will solve most of the problems people have with Python 3.8, but people should migrate to AsyncMock.
I will try to find some time to look at this patch soon, but I'm not committing on anything.
Le jeu. 30 avr. 2020 à 10:41, Andrej Shadura [email protected] a écrit :
@Martiusweb https://github.com/Martiusweb, any updates on this? As Python 3.8 is becoming the default in distros (e.g. Debian), these issues become serious.
See e.g. #954554 https://bugs.debian.org/954554
cc #132 https://github.com/Martiusweb/asynctest/issues/132
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Martiusweb/asynctest/pull/134#issuecomment-621697933, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABPWGG7ACITO32XJWZJPC3RPE2SZANCNFSM4IDOQIFQ .
-- Martin http://www.martiusweb.net Richard www.martiusweb.net
Any progress on this?
Could use this fix too, any updates?