Skip to content

unittest: fix class instances no longer released on test teardown since pytest 8.2.0#12368

Merged
bluetech merged 1 commit intopytest-dev:mainfrom
bluetech:unittest-clear-instance
May 26, 2024
Merged

unittest: fix class instances no longer released on test teardown since pytest 8.2.0#12368
bluetech merged 1 commit intopytest-dev:mainfrom
bluetech:unittest-clear-instance

Conversation

@bluetech
Copy link
Copy Markdown
Member

Fix #12367.

Comment thread testing/test_unittest.py
@@ -192,30 +191,32 @@ def test_check(self):
def test_teardown_issue1649(pytester: Pytester) -> None:
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The way this test was written previously wasn't good; it checked if the obj is still alive after the pytester run, at which the entire session was torn down, too late. This fixes it up. I made sure it now fails before and passes after.

Comment thread src/_pytest/unittest.py
super().setup()

def teardown(self) -> None:
super().teardown()
Copy link
Copy Markdown
Member Author

@bluetech bluetech May 25, 2024

Choose a reason for hiding this comment

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

This change isn't really related and doesn't have any effect because the super call doesn't do anything, but nonetheless teardown must be done in reverse order, so I fixed it just in case the super ever starts doing something.

Comment thread testing/test_unittest.py
@bluetech bluetech force-pushed the unittest-clear-instance branch from ff9caa8 to c3c5103 Compare May 26, 2024 07:18
@bluetech bluetech merged commit f8dfc1d into pytest-dev:main May 26, 2024
@bluetech bluetech deleted the unittest-clear-instance branch May 26, 2024 07:34
@mdmintz
Copy link
Copy Markdown

mdmintz commented Jun 5, 2024

@bluetech I think these changes caused #12424

@marcoep marcoep mentioned this pull request Jun 8, 2024
4 tasks
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.

Unittest class instances no longer released on test teardown since pytest 8.2.0

3 participants