Skip to content

gh-102402: Fix logging test_relativeCreated_has_higher_precision() leak #117985

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

Merged
merged 2 commits into from
Apr 18, 2024

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Apr 17, 2024

Fix a reference leak in test_relativeCreated_has_higher_precision() of test_logging: don't reimport the logging the logging module.

…n() leak

Fix a reference leak in test_relativeCreated_has_higher_precision()
of test_logging: don't reimport the logging the logging module.
@vstinner
Copy link
Member Author

@vsajip @serhiy-storchaka: Would you mind to review my fix?

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

It looks like an intermediate version of this test. I did not like it. It relies on implementation details -- that _startTime exists, that it is initialize with the time as nanoseconds, and that there are no other variables that depend on the starting time. If we rely so much on these details, we could simply not add this test at first place.

I tried to re-import a new logging module with its submodules. It seems not working too. Perhaps the only solution is to run a script which patches time_ns() before the first import of logging.

It is still unsolved mistery why re-importing the logging module leaks.

@vstinner
Copy link
Member Author

It relies on implementation details -- that _startTime exists, that it is initialize with the time as nanoseconds, and that there are no other variables that depend on the starting time.

The test can be marked as @cpython_only if needed. The test already makes the assumption that the logging module uses time.time_ns(). What if it uses time.time() on PyPy, or what if it uses time.monotonic_ns(), etc.?

Creating a new module instance is causing too much trouble. For example, it calls os.register_at_fork() which cannot be unregistered, unless the function is mocked as well. That's just an example: commenting this code is not enough to fix the leak.

@vstinner
Copy link
Member Author

The test can be marked as @cpython_only if needed.

Done.

@vstinner vstinner merged commit 8f25cc9 into python:main Apr 18, 2024
31 checks passed
@vstinner vstinner deleted the fix_test_logging_leak branch April 18, 2024 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
skip news tests Tests in the Lib/test dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants