Skip to content

Commit

Permalink
MAINT: Be dilligent about closing files (causes warnings on python >=…
Browse files Browse the repository at this point in the history
…3.8)
  • Loading branch information
wosc committed Feb 8, 2022
1 parent f703f1a commit b4fa787
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion core/src/zeit/cms/testing.py
Expand Up @@ -198,7 +198,8 @@ def assert_non_browser_modules_have_no_browser_zcml(self):
if not os.path.exists(configure_zcml):
return # be defensive

zcml = open(configure_zcml).read().splitlines()
with open(configure_zcml) as f:
zcml = f.read().splitlines()
for directive in ['namespaces.zope.org/browser', 'gocept:pagelet']:
for i, line in enumerate(zcml):
if directive in line:
Expand Down

2 comments on commit b4fa787

@fschulze
Copy link
Contributor

Choose a reason for hiding this comment

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

I tried seeing ResourceWarnings in another project. I had to enable them with -W once::ResourceWarning in pytest, do you have that somewhere? I couldn't find it.

The output is often unhelpful, so I added this feature proposal to pytest: pytest-dev/pytest#9644

@wosc
Copy link
Member Author

@wosc wosc commented on b4fa787 Feb 8, 2022

Choose a reason for hiding this comment

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

I've been experimenting with filterwarnings = error recently, which surfaced this issue (under python-3.9, but not 3.7 IIRC). The traceback was tolerable:

# snip
  File "/usr/local/lib/python3.9/site-packages/_pytest/unraisableexception.py", line 78, in unraisable_exception_runtest_hook
    warnings.warn(pytest.PytestUnraisableExceptionWarning(msg))
pytest.PytestUnraisableExceptionWarning: Exception ignored in: <_io.FileIO [closed]>

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/zeit/cms/testing.py", line 201, in assert_non_browser_modules_have_no_browser_zcml
    zcml = open(configure_zcml).read().splitlines()
ResourceWarning: unclosed file <_io.TextIOWrapper name='/usr/local/lib/python3.9/site-packages/zeit/connector/configure.zcml' mode='r' encoding='UTF-8'>

Please sign in to comment.