|
2 | 2 |
|
3 | 3 | import argparse |
4 | 4 | import os |
| 5 | +import re |
5 | 6 | import warnings |
6 | 7 | from io import StringIO |
7 | 8 | from pathlib import Path |
|
22 | 23 | if TYPE_CHECKING: |
23 | 24 | from .engine import CovController |
24 | 25 |
|
| 26 | +COVERAGE_SQLITE_WARNING_RE = re.compile('unclosed database in <sqlite3.Connection object at', re.I) |
| 27 | + |
25 | 28 |
|
26 | 29 | def validate_report(arg): |
27 | 30 | file_choices = ['annotate', 'html', 'xml', 'json', 'lcov'] |
@@ -315,9 +318,21 @@ def _should_report(self): |
315 | 318 | @pytest.hookimpl(hookwrapper=True) |
316 | 319 | def pytest_runtestloop(self, session): |
317 | 320 | # override some warning configuration to prevent certain warnings to bubble up as errors due to rigid filterwarnings configuration |
318 | | - warnings.filterwarnings('default', 'unclosed database in <sqlite3.Connection object at', ResourceWarning) |
319 | | - warnings.simplefilter('once', PytestCovWarning) |
320 | | - warnings.simplefilter('once', CoverageWarning) |
| 321 | + for _, message, category, _, _ in warnings.filters: |
| 322 | + if category is ResourceWarning and message == COVERAGE_SQLITE_WARNING_RE: |
| 323 | + break |
| 324 | + else: |
| 325 | + warnings.filterwarnings('default', 'unclosed database in <sqlite3.Connection object at', ResourceWarning) |
| 326 | + for _, _, category, _, _ in warnings.filters: |
| 327 | + if category is PytestCovWarning: |
| 328 | + break |
| 329 | + else: |
| 330 | + warnings.simplefilter('once', PytestCovWarning) |
| 331 | + for _, _, category, _, _ in warnings.filters: |
| 332 | + if category is CoverageWarning: |
| 333 | + break |
| 334 | + else: |
| 335 | + warnings.simplefilter('once', CoverageWarning) |
321 | 336 |
|
322 | 337 | yield |
323 | 338 |
|
|
0 commit comments