Merge pull request #5729 from Stranger6667/issue-5115

Do not treat warnings as errors during ``pytest_configure``.
This commit is contained in:
Bruno Oliveira 2019-08-15 08:05:15 -03:00 committed by GitHub
commit 0a62c4ac04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 1 deletions

View File

@ -0,0 +1 @@
Warnings issued during ``pytest_configure`` are explicitly not treated as errors, even if configured as such, because it otherwise completely breaks pytest.

View File

@ -642,6 +642,8 @@ class Config:
def _do_configure(self):
assert not self._configured
self._configured = True
with warnings.catch_warnings():
warnings.simplefilter("default")
self.hook.pytest_configure.call_historic(kwargs=dict(config=self))
def _ensure_unconfigure(self):

View File

@ -645,3 +645,21 @@ def test_group_warnings_by_message(testdir):
warning_code = 'warnings.warn(UserWarning("foo"))'
assert warning_code in result.stdout.str()
assert result.stdout.str().count(warning_code) == 1
def test_pytest_configure_warning(testdir, recwarn):
"""Issue 5115."""
testdir.makeconftest(
"""
def pytest_configure():
import warnings
warnings.warn("from pytest_configure")
"""
)
result = testdir.runpytest()
assert result.ret == 5
assert "INTERNALERROR" not in result.stderr.str()
warning = recwarn.pop()
assert str(warning.message) == "from pytest_configure"