Capture and display warnings during collection

Fix #3251
This commit is contained in:
Bruno Oliveira
2018-08-26 11:09:54 -03:00
parent 51e32cf7cc
commit 1a9d913ee1
4 changed files with 51 additions and 13 deletions
+25
View File
@@ -321,3 +321,28 @@ def test_warning_captured_hook(testdir, pyfile_with_warnings):
(RuntimeWarning, "runtest", "test_func"),
]
assert collected == expected
@pytest.mark.filterwarnings("always")
def test_collection_warnings(testdir):
"""
"""
testdir.makepyfile(
"""
import warnings
warnings.warn(UserWarning("collection warning"))
def test_foo():
pass
"""
)
result = testdir.runpytest()
result.stdout.fnmatch_lines(
[
"*== %s ==*" % WARNINGS_SUMMARY_HEADER,
"*collection_warnings.py:3: UserWarning: collection warning",
' warnings.warn(UserWarning("collection warning"))',
"* 1 passed, 1 warnings*",
]
)