Skip to content

Conversation

@timj
Copy link
Member

@timj timj commented Nov 5, 2025

This doesn't fix the warnings from pytest-cov with scons -jN. Maybe we need to set PYTHONWARNINGS env var instead.

cc/ @andy-slac

@codecov
Copy link

codecov bot commented Nov 5, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.81%. Comparing base (637bcd0) to head (1d79d41).
⚠️ Report is 2 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@timj timj requested a review from andy-slac November 5, 2025 21:26
Copy link

@andy-slac andy-slac left a 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 -W option or PYTHONWARNINGS with ignore:unclosed database in <sqlite3.Connection object at:ResourceWarning string, the message string is escaped before it is compiled, and the result is re.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.

@andy-slac
Copy link

I made a PR for pytest-cov: pytest-dev/pytest-cov#727

@timj timj force-pushed the tickets/DM-53178 branch from 9393e2d to 1d79d41 Compare November 6, 2025 04:49
@timj timj merged commit 50719a3 into main Nov 6, 2025
17 of 18 checks passed
@timj timj deleted the tickets/DM-53178 branch November 6, 2025 15:46
@timj
Copy link
Member Author

timj commented Nov 6, 2025

I had tried putting the filterwarnings in the pyproject.toml but it didn't work if -Wd was used.

@andy-slac
Copy link

I had tried putting the filterwarnings in the pyproject.toml but it didn't work if -Wd was used.

filterwarnings needs to be done in addition to -W "ignore:... to suppress few remaining warnings (basically to force pytest-cov not to add its filter).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants