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

Bugfix/126 coroutine deprecated warnings #134

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Bugfix/126 coroutine deprecated warnings #134

wants to merge 2 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Jul 14, 2019

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.

@ghost
Copy link
Author

ghost commented Jul 14, 2019

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.

@Martiusweb
Copy link
Owner

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.

@andrewshadura
Copy link

andrewshadura commented Apr 30, 2020

@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

@Martiusweb
Copy link
Owner

Martiusweb commented Apr 30, 2020 via email

@Askaholic
Copy link

Any progress on this?

@Lordnibbler
Copy link

Could use this fix too, any updates?

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.

4 participants