Skip to content

Treat methodName="runTest" similar to unittest.TestCase#373

Merged
jelmer merged 2 commits intotesting-cabal:masterfrom
ncopa:fix-pytest-8.2
May 13, 2024
Merged

Treat methodName="runTest" similar to unittest.TestCase#373
jelmer merged 2 commits intotesting-cabal:masterfrom
ncopa:fix-pytest-8.2

Conversation

@ncopa
Copy link
Copy Markdown
Contributor

@ncopa ncopa commented 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: #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 ncopa force-pushed the fix-pytest-8.2 branch 2 times, most recently from fb822a8 to e4f0b99 Compare May 13, 2024 12:21
@jelmer jelmer enabled auto-merge May 13, 2024 12:29
Copy link
Copy Markdown
Member

@jelmer jelmer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please run ruff format, otherwise LGTM

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)
auto-merge was automatically disabled May 13, 2024 13:26

Head branch was pushed to by a user without write access

@ncopa ncopa force-pushed the fix-pytest-8.2 branch from b56a638 to 91e617a Compare May 13, 2024 13:26
@ncopa
Copy link
Copy Markdown
Contributor Author

ncopa commented May 13, 2024

ruff formatted it (I hope). sorry for that.

@ncopa ncopa requested a review from jelmer May 13, 2024 13:33
@jelmer jelmer enabled auto-merge May 13, 2024 13:41
@jelmer jelmer merged commit 48e689b into testing-cabal:master May 13, 2024
@ncopa ncopa deleted the fix-pytest-8.2 branch May 13, 2024 15:07
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.

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

2 participants