pytest icon indicating copy to clipboard operation
pytest copied to clipboard

Issue with pytest 8.2.0 and tornado async tests

Open arossert opened this issue 1 year ago • 4 comments

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

arossert avatar Apr 28 '24 08:04 arossert

Thanks the report, I will look into it.

bluetech avatar Apr 28 '24 08:04 bluetech

  • Regressed in 1a5e0eb71d2af0ad113ccd9ee596c7d724d7a4b6

  • That commit relies on a feature of unittest.TestCase where initializing it with the default methodName="runTest" is treated specially, allowing to instantiate even without runTest method 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.

bluetech avatar Apr 28 '24 10:04 bluetech

@cylc/uiserver has hit the same issue.

wxtim avatar Apr 29 '24 13:04 wxtim

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: ...

bluetech avatar May 13 '24 10:05 bluetech

This is fixed in Tornado 6.4.1: https://www.tornadoweb.org/en/stable/releases/v6.4.1.html

bluetech avatar Jun 07 '24 06:06 bluetech