-
Notifications
You must be signed in to change notification settings - Fork 11
DM-53178: Ignore sqlite resource warnings in tests #138
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
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #138 +/- ##
==========================================
- Coverage 85.36% 81.81% -3.55%
==========================================
Files 5 2 -3
Lines 41 33 -8
Branches 3 3
==========================================
- Hits 35 27 -8
Misses 3 3
Partials 3 3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
andy-slac
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks OK. I tried to understand where that remaining warning comes from and I found a big mess in pytest and pytest-cov handling of warnings:
- For some stupid reasons pytest-cov think that they need to enable warnings for
sqlite ResourceWarnings. - But they check existing warning filters to see if there is already a filter for that warning. They check for message
re.compile('unclosed database in <sqlite3.Connection object at', re.I), if that filter exists, they don't add a new filter. - When you use
-Woption orPYTHONWARNINGSwithignore:unclosed database in <sqlite3.Connection object at:ResourceWarningstring, the message string is escaped before it is compiled, and the result isre.compile('unclosed\\ database\\ in\\ <sqlite3\\.Connection\\ object\\ at', re.I), which does not match what pytest-cov expects. - Another complication (that helps us) is that pytest uses
-W...option to set temporary filters for each test case, which masks pytest-cov filter. But after all test cases are done, garbage collection kills sqlite connection and at that point it generates ResourceWarning, but with pytest-cov filter is active again.
Also, if you add
[tool.pytest.ini_options]
filterwarnings = [
"default",
"ignore:unclosed database in <sqlite3.Connection object at:ResourceWarning",
]
to pyproject.toml then the string is not escaped before compiling into re, and it does match what pytest-cov expects. But that does not help us very much as this needs to be added to each package that uses buler in tests.
I think we need to make a ticket for pytest-cov guys.
|
I made a PR for pytest-cov: pytest-dev/pytest-cov#727 |
9393e2d to
1d79d41
Compare
|
I had tried putting the filterwarnings in the pyproject.toml but it didn't work if |
|
This doesn't fix the warnings from pytest-cov with
scons -jN. Maybe we need to set PYTHONWARNINGS env var instead.cc/ @andy-slac