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

Pytest 8: AttributeError: 'TestExpectedException' object has no attribute 'runTest'. Did you mean: 'subTest'? #372

Closed
hrnciar opened this issue May 7, 2024 · 3 comments · Fixed by #373

Comments

@hrnciar
Copy link

hrnciar commented May 7, 2024

Hello,

we are using pytest for running bandit and python-etcd3gw tests. Since pytest 8 the tests are failing with AttributeError: 'XXX' object has no attribute 'runTest'. Did you mean: 'subTest'?
See:

Reproducer:

$ git clone [email protected]:testing-cabal/testtools.git
$ cd testtools
[testtools (master)]$ tox -e py312
...

[testtools (master)]$ .tox/py312/bin/pip install 'pytest>=8'
[testtools (master)]$ .tox/py312/bin/pytest testtools/tests
...
AttributeError: 'TestExpectedException' object has no attribute 'runTest'. Did you mean: 'subTest'?
11 warnings, 218 errors

[testtools (master)]$ .tox/py312/bin/pip install 'pytest<8'
[testtools (master)]$ .tox/py312/bin/pytest testtools/tests
...
38 failed, 1328 passed, 7 skipped, 2 xfailed, 59 warnings
@jelmer
Copy link
Member

jelmer commented May 7, 2024

Please use either the test tools test runner or the native python test runner (unittest)

We're open to PRs that improve support for running the test with third party runners like pytest, but it's not a priority for the project.

@jelmer
Copy link
Member

jelmer commented May 7, 2024

See also #332

@jelmer jelmer closed this as not planned Won't fix, can't repro, duplicate, stale May 7, 2024
@ncopa
Copy link
Contributor

ncopa commented May 13, 2024

Details why this happens is found here pytest-dev/pytest#12263 (comment)

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)
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)
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 a pull request may close this issue.

3 participants