Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/5115.bugfix.rst
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 3 additions & 1 deletion src/_pytest/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,9 @@ def add_cleanup(self, func):
def _do_configure(self):
assert not self._configured
self._configured = True
self.hook.pytest_configure.call_historic(kwargs=dict(config=self))
with warnings.catch_warnings():
warnings.simplefilter("default")
self.hook.pytest_configure.call_historic(kwargs=dict(config=self))

def _ensure_unconfigure(self):
if self._configured:
Expand Down
18 changes: 18 additions & 0 deletions testing/test_warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"