pytest
pytest copied to clipboard
Issue with pytest 8.2.0 and tornado async tests
I'm using the AsyncHTTPTestCase and AsyncHTTPSTestCase from tornado and the latest pytest fails in collection on this error:
Error
collection failure
Stacktrace
usr/local/lib/python3.8/site-packages/tornado/testing.py:180: in __init__
setattr(self, methodName, _TestMethodWrapper(getattr(self, methodName)))
E AttributeError: 'AsyncHTTPTestCase' object has no attribute 'runTest'
The issue does not exists in 8.1.0
Thanks the report, I will look into it.
-
Regressed in 1a5e0eb71d2af0ad113ccd9ee596c7d724d7a4b6
-
That commit relies on a feature of
unittest.TestCasewhere initializing it with the defaultmethodName="runTest"is treated specially, allowing to instantiate even withoutrunTestmethod actually existing. This is documented under "Changed in Python 3.2" in unittest.TestCase docs. -
Tornado doesn't follow this, assumes that the methodName exists even with the default.
My preference would be to fix Tornado, I will try to submit a patch. Otherwise will fix in pytest somehow.
@cylc/uiserver has hit the same issue.
Some projects (like mine) use a common base TestCase class. If you do this, you can work around this issue by adding a dummy runTest method, like this:
class BaseTestCase(AsyncTestCase):
# Workaround for https://github.com/pytest-dev/pytest/issues/12263.
def runTest(self): pass
Another workaround, more intrusive but I think harmless and easier, is to drop the following in a contest.py file at the root of your testing directory:
from tornado.testing import AsyncTestCase
# Workaround for https://github.com/pytest-dev/pytest/issues/12263.
AsyncTestCase.runTest = lambda self: ...
This is fixed in Tornado 6.4.1: https://www.tornadoweb.org/en/stable/releases/v6.4.1.html