Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add default filterwarning configuration#696

Merged
ionelmc merged 9 commits into
master from
issue-693
Jun 11, 2025
Merged

Add default filterwarning configuration #696
ionelmc merged 9 commits into
master from
issue-693

Conversation

@ionelmc

@ionelmc ionelmc commented Jun 6, 2025

Copy link
Copy Markdown
Member

No description provided.

@ionelmc ionelmc changed the title (削除) Add reproducer for #693. (削除ここまで) (追記) Add default filterwarning configuration (追記ここまで) Jun 11, 2025
@ionelmc ionelmc merged commit f69166a into master Jun 11, 2025
180 of 182 checks passed
@ionelmc ionelmc deleted the issue-693 branch June 11, 2025 21:53
Comment thread src/pytest_cov/plugin.py
if TYPE_CHECKING:
from .engine import CovController

COVERAGE_SQLITE_WARNING_RE = re.compile('unclosed database in <sqlite3.Connection object at', re.I)

@reactive-firewall reactive-firewall Jun 11, 2025

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM; with conditions:

NIT - the pattern string could have be abstracted for use later
Suggested change
COVERAGE_SQLITE_WARNING_RE = re.compile('unclosed database in <sqlite3.Connection object at', re.I)
COVERAGE_SQLITE_WARNING_STUB = 'unclosed database in <sqlite3.Connection object at'
COVERAGE_SQLITE_WARNING_RE = re.compile(COVERAGE_SQLITE_WARNING_STUB, re.I)

and later used to simplify:

 for _, message, category, _, _ in warnings.filters:
 if category is ResourceWarning and message == COVERAGE_SQLITE_WARNING_RE:
 break
 else:
 warnings.filterwarnings('default', 'unclosed database in <sqlite3.Connection object at', ResourceWarning)

with the patch:

 for _, message, category, _, _ in warnings.filters:
 if category is ResourceWarning and message == COVERAGE_SQLITE_WARNING_RE:
 break
 else:
- warnings.filterwarnings('default', 'unclosed database in <sqlite3.Connection object at', ResourceWarning)
+ warnings.filterwarnings('default', COVERAGE_SQLITE_WARNING_STUB, ResourceWarning)

yielding:

 for _, message, category, _, _ in warnings.filters:
 if category is ResourceWarning and message == COVERAGE_SQLITE_WARNING_RE:
 break
 else:
 warnings.filterwarnings('default', COVERAGE_SQLITE_WARNING_STUB, ResourceWarning)

Comment thread src/pytest_cov/plugin.py
if category is ResourceWarning and message == COVERAGE_SQLITE_WARNING_RE:
break
else:
warnings.filterwarnings('default', 'unclosed database in <sqlite3.Connection object at', ResourceWarning)

@reactive-firewall reactive-firewall Jun 11, 2025

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM; with continued conditions:

NIT - Could be more DRY

As mentioned already, this string could be set with the RE variable so that only the base string need be ever updated 🤷

e.g.,

COVERAGE_SQLITE_WARNING_STUB = 'unclosed database in <sqlite3.Connection object at'
COVERAGE_SQLITE_WARNING_RE = re.compile(COVERAGE_SQLITE_WARNING_STUB, re.I)

and refactor this line to:

Suggested change
warnings.filterwarnings('default', 'unclosed database in <sqlite3.Connection object at', ResourceWarning)
warnings.filterwarnings('default', COVERAGE_SQLITE_WARNING_STUB, ResourceWarning)

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

Reviewers

1 more reviewer

@reactive-firewall reactive-firewall reactive-firewall left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /