Skip to content

Commit 9dabad3

Browse files
committed
Do not mess with the warnings if the plugin is disabled. Also, upgrade to new style hook.
1 parent 222e991 commit 9dabad3

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/pytest_cov/plugin.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,12 @@ def _should_report(self):
315315

316316
# we need to wrap pytest_runtestloop. by the time pytest_sessionfinish
317317
# runs, it's too late to set testsfailed
318-
@pytest.hookimpl(hookwrapper=True)
318+
@pytest.hookimpl(wrapper=True)
319319
def pytest_runtestloop(self, session):
320-
# override some warning configuration to prevent certain warnings to bubble up as errors due to rigid filterwarnings configuration
320+
if self._disabled:
321+
return (yield)
322+
323+
# we add default warning configuration to prevent certain warnings to bubble up as errors due to rigid filterwarnings configuration
321324
for _, message, category, _, _ in warnings.filters:
322325
if category is ResourceWarning and message == COVERAGE_SQLITE_WARNING_RE:
323326
break
@@ -334,10 +337,7 @@ def pytest_runtestloop(self, session):
334337
else:
335338
warnings.simplefilter('once', CoverageWarning)
336339

337-
yield
338-
339-
if self._disabled:
340-
return
340+
result = yield
341341

342342
compat_session = compat.SessionWrapper(session)
343343

@@ -372,6 +372,8 @@ def pytest_runtestloop(self, session):
372372
# make sure we get the EXIT_TESTSFAILED exit code
373373
compat_session.testsfailed += 1
374374

375+
return result
376+
375377
def write_heading(self, terminalreporter):
376378
if not self._wrote_heading:
377379
terminalreporter.write_sep('=', 'tests coverage')

0 commit comments

Comments
 (0)