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

Issue with pytest 8.2.0 and tornado async tests #12263

Open
arossert opened this issue Apr 28, 2024 · 4 comments
Open

Issue with pytest 8.2.0 and tornado async tests #12263

arossert opened this issue Apr 28, 2024 · 4 comments
Labels
plugin: unittest related to the unittest integration builtin plugin type: regression indicates a problem that was introduced in a release which was working previously

Comments

@arossert
Copy link

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

@bluetech
Copy link
Member

Thanks the report, I will look into it.

@bluetech
Copy link
Member

  • Regressed in 1a5e0eb

  • 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 added a commit to bluetech/tornado that referenced this issue Apr 28, 2024
`unittest.TestCase` has a feature where it allows instantiating
`MyTestClass()` with the default method name `runTest` even if a
`runTest` method doesn't actually exist. This is documented in
`TestCase`'s docs under "Changed in version 3.2"[0].

Since version 8.2, pytest relies on this, and started breaking on
Tornado's `AsyncTestCase`[1].

Change `AsyncTestCase` to allow empty instatiation, by matching the
upstream code.

[0] https://docs.python.org/3/library/unittest.html#unittest.TestCase
[1] pytest-dev/pytest#12263
alex added a commit to alex/mitmproxy that referenced this issue Apr 29, 2024
mhils pushed a commit to mitmproxy/mitmproxy that referenced this issue Apr 29, 2024
kajarenc pushed a commit to streamlit/streamlit that referenced this issue Apr 29, 2024
## Describe your changes
- Looks like pytest 8.2 breaks with tornado
- As a result, we should likely pin 8.1 pytest
- pytest-dev/pytest#12263
## GitHub Issue Link (if applicable)

## Testing Plan

- Explanation of why no additional tests are needed
- Unit Tests (JS and/or Python)
- E2E Tests
- Any manual testing needed?

---

**Contribution License Agreement**

By submitting this pull request you agree that all contributions to this
project are made under the Apache 2.0 license.
@wxtim

This comment was marked as outdated.

wxtim added a commit to wxtim/cylc-uiserver that referenced this issue Apr 29, 2024
MetRonnie pushed a commit to cylc/cylc-uiserver that referenced this issue Apr 29, 2024
kmcgrady pushed a commit to streamlit/streamlit that referenced this issue May 2, 2024
## Describe your changes
- Looks like pytest 8.2 breaks with tornado
- As a result, we should likely pin 8.1 pytest
- pytest-dev/pytest#12263
## GitHub Issue Link (if applicable)

## Testing Plan

- Explanation of why no additional tests are needed
- Unit Tests (JS and/or Python)
- E2E Tests
- Any manual testing needed?

---

**Contribution License Agreement**

By submitting this pull request you agree that all contributions to this
project are made under the Apache 2.0 license.
algitbot pushed a commit to alpinelinux/aports that referenced this issue May 12, 2024
@Zac-HD Zac-HD added type: regression indicates a problem that was introduced in a release which was working previously plugin: unittest related to the unittest integration builtin plugin labels May 13, 2024
ncopa added a commit to ncopa/testtools that referenced this issue May 13, 2024
pytest 82. relies on a feature of `unittest.TestCase` where the
initialization of it with the default `methodName="runTest"` is treated
specially, allowing it to insantiate even without `runTest` method
actually existing.

See under "Changed in Python 3.2" in unittest.TestCase docs

This fixes the error with pytest 8.2:
  AttributeError: 'TestUtil' object has no attribute 'runTest'. Did you mean: 'subTest'?

Fixes: testing-cabal#372
ref: https://docs.python.org/3/library/unittest.html#unittest.TestCase
ref: https://github.com/python/cpython/blob/51aefc5bf907ddffaaf083ded0de773adcdf08c8/Lib/unittest/case.py#L419-L426
ref: pytest-dev/pytest#12263 (comment)
ncopa added a commit to ncopa/testtools that referenced this issue May 13, 2024
pytest 8.2 relies on a feature of `unittest.TestCase` where the
initialization of it with the default `methodName="runTest"` is treated
specially, allowing it to insantiate even without `runTest` method
actually existing.

See under "Changed in Python 3.2" in unittest.TestCase docs

This fixes the error with pytest 8.2:
  AttributeError: 'TestUtil' object has no attribute 'runTest'. Did you mean: 'subTest'?

Fixes: testing-cabal#372
ref: https://docs.python.org/3/library/unittest.html#unittest.TestCase
ref: https://github.com/python/cpython/blob/51aefc5bf907ddffaaf083ded0de773adcdf08c8/Lib/unittest/case.py#L419-L426
ref: pytest-dev/pytest#12263 (comment)
@bluetech
Copy link
Member

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

ncopa added a commit to ncopa/testtools that referenced this issue May 13, 2024
pytest 8.2 relies on a feature of `unittest.TestCase` where the
initialization of it with the default `methodName="runTest"` is treated
specially, allowing it to insantiate even without `runTest` method
actually existing.

See under "Changed in Python 3.2" in unittest.TestCase docs

This fixes the error with pytest 8.2:
  AttributeError: 'TestUtil' object has no attribute 'runTest'. Did you mean: 'subTest'?

Fixes: testing-cabal#372
ref: https://docs.python.org/3/library/unittest.html#unittest.TestCase
ref: https://github.com/python/cpython/blob/51aefc5bf907ddffaaf083ded0de773adcdf08c8/Lib/unittest/case.py#L419-L426
ref: pytest-dev/pytest#12263 (comment)
jelmer pushed a commit to ncopa/testtools that referenced this issue May 13, 2024
pytest 8.2 relies on a feature of `unittest.TestCase` where the
initialization of it with the default `methodName="runTest"` is treated
specially, allowing it to insantiate even without `runTest` method
actually existing.

See under "Changed in Python 3.2" in unittest.TestCase docs

This fixes the error with pytest 8.2:
  AttributeError: 'TestUtil' object has no attribute 'runTest'. Did you mean: 'subTest'?

Fixes: testing-cabal#372
ref: https://docs.python.org/3/library/unittest.html#unittest.TestCase
ref: https://github.com/python/cpython/blob/51aefc5bf907ddffaaf083ded0de773adcdf08c8/Lib/unittest/case.py#L419-L426
ref: pytest-dev/pytest#12263 (comment)
ncopa added a commit to ncopa/testtools that referenced this issue May 13, 2024
pytest 8.2 relies on a feature of `unittest.TestCase` where the
initialization of it with the default `methodName="runTest"` is treated
specially, allowing it to insantiate even without `runTest` method
actually existing.

See under "Changed in Python 3.2" in unittest.TestCase docs

This fixes the error with pytest 8.2:
  AttributeError: 'TestUtil' object has no attribute 'runTest'. Did you mean: 'subTest'?

Fixes: testing-cabal#372
ref: https://docs.python.org/3/library/unittest.html#unittest.TestCase
ref: https://github.com/python/cpython/blob/51aefc5bf907ddffaaf083ded0de773adcdf08c8/Lib/unittest/case.py#L419-L426
ref: pytest-dev/pytest#12263 (comment)
imjoehaines added a commit to bugsnag/bugsnag-python that referenced this issue May 20, 2024
imjoehaines added a commit to bugsnag/bugsnag-python that referenced this issue May 20, 2024
imjoehaines added a commit to bugsnag/bugsnag-python that referenced this issue May 20, 2024
alex added a commit to alex/mitmproxy that referenced this issue May 20, 2024
mhils pushed a commit to mitmproxy/mitmproxy that referenced this issue May 20, 2024
imjoehaines added a commit to bugsnag/bugsnag-python that referenced this issue May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin: unittest related to the unittest integration builtin plugin type: regression indicates a problem that was introduced in a release which was working previously
Projects
None yet
Development

No branches or pull requests

4 participants