Skip to content

bpo-44515: handle non-refcounted GC in contextlib tests#26910

Merged
ambv merged 3 commits into
python:mainfrom
ncoghlan:bpo-44515-make-contextlib-tests-pypy3-compatible
Jul 26, 2021
Merged

bpo-44515: handle non-refcounted GC in contextlib tests#26910
ambv merged 3 commits into
python:mainfrom
ncoghlan:bpo-44515-make-contextlib-tests-pypy3-compatible

Conversation

@ncoghlan

@ncoghlan ncoghlan commented Jun 26, 2021

Copy link
Copy Markdown
Contributor

Comment thread Lib/test/test_contextlib.py Outdated
a = weakref.ref(a)
b = weakref.ref(b)
# Allow test to work with a non-refcounted GC
gc.collect(); gc.collect(); gc.collect()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there a reason this needs to be done three times?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It ensures references are still cleaned up even if they've made it out of the "recently allocated" generation in a GC that tracks generations.

Before we merge, I want to check the rest of the test suite to see if this is still the recommended practice for forcing collection, or if there'sa helper in test.support these days.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There is test.support.gc_collect(), which does also do it three times.

@ambv ambv merged commit a2c45e5 into python:main Jul 26, 2021
@miss-islington

Copy link
Copy Markdown
Contributor

Thanks @ncoghlan for the PR, and @ambv for merging it 🌮🎉.. I'm working now to backport this PR to: 3.10.
🐍🍒⛏🤖

@bedevere-bot

Copy link
Copy Markdown

GH-27379 is a backport of this pull request to the 3.10 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 26, 2021
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
(cherry picked from commit a2c45e5)

Co-authored-by: Nick Coghlan <ncoghlan@gmail.com>
sthagen added a commit to sthagen/python-cpython that referenced this pull request Jul 26, 2021
bpo-44515: handle non-refcounted GC in contextlib tests (pythonGH-26910)
ambv pushed a commit that referenced this pull request Jul 26, 2021
…H-27379)

Co-authored-by: Łukasz Langa <lukasz@langa.pl>
(cherry picked from commit a2c45e5)

Co-authored-by: Nick Coghlan <ncoghlan@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants