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

Close opened resource. #235

Merged
merged 4 commits into from
Nov 3, 2019
Merged

Close opened resource. #235

merged 4 commits into from
Nov 3, 2019

Conversation

krzysztof-pawlik-gat
Copy link
Contributor

When using custom CSS file I'm getting following warning:

/home/nelchael/.local/share/virtualenvs/functional-tests-IjeTcJ7i/lib/python3.7/site-packages/pytest_html/plugin.py:71: ResourceWarning: unclosed file <_io.TextIOWrapper name='resources/pytest-html-custom.css' mode='r' encoding='UTF-8'>
  open(csspath)
ResourceWarning: Enable tracemalloc to get the object allocation traceback

This fixes it by closing the opened file. If I'm understanding it correctly, the file is opened just to make sure it exists here, so it could be potentially replaced with os.access call, but it's entirely optional.

@BeyondEvil
Copy link
Contributor

It is possible to add a test for this? Essentially checking that we get the warning prior to the fix, and don't get it after the fix? @krzysztof-pawlik-gat

pytest_html/plugin.py Outdated Show resolved Hide resolved
@krzysztof-pawlik-gat
Copy link
Contributor Author

It is possible to add a test for this? Essentially checking that we get the warning prior to the fix, and don't get it after the fix? @krzysztof-pawlik-gat

Sorry for the late response, but yes and it's actually quite easy - added modifications to tests in 05ac9a8 (checked with the fix reverted and tests fail due to warnings, with the fix tests pass as expected).

Copy link
Contributor

@BeyondEvil BeyondEvil left a comment

Choose a reason for hiding this comment

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

LGTM!

@BeyondEvil BeyondEvil merged commit 7166364 into pytest-dev:master Nov 3, 2019
@krzysztof-pawlik-gat krzysztof-pawlik-gat deleted the fix-resource-warning branch November 4, 2019 06:13
wanam added a commit to wanam/pytest-html that referenced this pull request Nov 4, 2019
@ssbarnea ssbarnea added the bug This issue/PR relates to a bug. label Aug 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue/PR relates to a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants