Skip to content
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

Fix ResourceWarning: unclosed file in Action #1179

Merged
merged 1 commit into from Mar 8, 2019
Merged

Fix ResourceWarning: unclosed file in Action #1179

merged 1 commit into from Mar 8, 2019

Conversation

@BoboTiG
Copy link
Contributor

@BoboTiG BoboTiG commented Mar 4, 2019

Hello,

Here is a patch to fix an annoying ResourceWarning: unclosed file I have on several projects when using tox. I did not find something better, but I am open to suggestions :)

FTR I used this fixture to ensure the fix is working well:

@pytest.fixture(autouse=True)
def no_warnings(recwarn):
    """Fail on warning."""

    yield

    warnings = []
    for warning in recwarn:  # pragma: no cover
        warnings.append("{w.filename}:{w.lineno} {w.message}".format(w=warning))
    assert not warnings

When encountering the related error, we could see this kind of warning:

tox/venv.py:545 unclosed file <_io.BufferedReader name='/tmp/pytest-of-tiger-222/pytest-55/popen-gw2/test_config_current_py0/.tox/py36/log/py36-0.log'>

I can add the fixture to the PR if you are interested (although it will need more work as there are other warnings while running the tests suite).

Contribution checklist:

  • wrote descriptive pull request text
  • added/updated test(s)
  • added news fragment in changelog folder
  • added yourself to CONTRIBUTORS (preserving alphabetical order)
Signed-off-by: Mickaël Schoentgen <contact@tiger-222.fr>
Copy link
Member

@asottile asottile left a comment

lg2m

@gaborbernat gaborbernat merged commit e189e5a into tox-dev:master Mar 8, 2019
5 checks passed
@BoboTiG BoboTiG deleted the fix-resource-warning-unclosed-file branch Mar 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants