-
Notifications
You must be signed in to change notification settings - Fork 216
Add default filterwarning configuration #696
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
from . import compat | ||
from . import embed | ||
|
||
if TYPE_CHECKING: | ||
from .engine import CovController | ||
|
||
COVERAGE_SQLITE_WARNING_RE = re.compile('unclosed database in <sqlite3.Connection object at', re.I) |
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.
LGTM; with conditions:
NIT - the pattern string could have be abstracted for use later
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)
if category is ResourceWarning and message == COVERAGE_SQLITE_WARNING_RE: | ||
break | ||
else: | ||
warnings.filterwarnings('default', 'unclosed database in <sqlite3.Connection object at', ResourceWarning) |
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.
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:
warnings.filterwarnings('default', 'unclosed database in <sqlite3.Connection object at', ResourceWarning) | |
warnings.filterwarnings('default', COVERAGE_SQLITE_WARNING_STUB, ResourceWarning) |
No description provided.