Skip to content

Conversation

@dimbleby
Copy link
Contributor

@dimbleby dimbleby commented Apr 5, 2023

I've been getting ResourceWarning for unclosed files from a handful of unit tests. The first commit in this MR wasn't the right guess, I eventually tracked it down to the second.

This looks like it's probably a bug somewhere in pytest I suppose, maybe some unexpected interaction between fixtures and capturing warnings.

This change strictly speaking makes the test less powerful - in the unlikely event that someone were to remove the deprecation warning the unit test wouldn't notice any more. But IMO it's better to live with that than with the false positives.

With any luck this all goes away soon anyway when #7356 completes the deprecation

before:

$ pytest -k test_add_no_constraint_old_installer
===================================================== test session starts =====================================================
platform linux -- Python 3.10.6, pytest-7.2.1, pluggy-1.0.0
Using --randomly-seed=335022381
rootdir: /home/dch/poetry, configfile: pyproject.toml, testpaths: tests
plugins: mock-3.10.0, xdist-3.2.0, cov-4.0.0, randomly-3.12.0
gw0 [1] / gw1 [1] / gw2 [1] / gw3 [1]
.                                                                                                                       [100%]
sys:1: ResourceWarning: unclosed file <_io.TextIOWrapper name=0 mode='r' encoding='UTF-8'>
sys:1: ResourceWarning: unclosed file <_io.TextIOWrapper name=1 mode='w' encoding='UTF-8'>

====================================================== 1 passed in 2.83s ======================================================

after

$ pytest -k test_add_no_constraint_old_installer
===================================================== test session starts =====================================================
platform linux -- Python 3.10.6, pytest-7.2.1, pluggy-1.0.0
Using --randomly-seed=3521203966
rootdir: /home/dch/poetry, configfile: pyproject.toml, testpaths: tests
plugins: mock-3.10.0, xdist-3.2.0, cov-4.0.0, randomly-3.12.0
gw0 [1] / gw1 [1] / gw2 [1] / gw3 [1]
.                                                                                                                       [100%]
====================================================== 1 passed in 2.01s ======================================================

@radoering radoering force-pushed the avoid-resource-warning branch from 2852deb to 158c055 Compare April 6, 2023 15:06
@radoering radoering enabled auto-merge (squash) April 6, 2023 15:06
@radoering radoering merged commit 860c838 into python-poetry:master Apr 6, 2023
@dimbleby dimbleby deleted the avoid-resource-warning branch April 6, 2023 15:38
@github-actions
Copy link

github-actions bot commented Mar 3, 2024

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants