Skip to content

Commit fa85371

Browse files
committed
Add test for #379
1 parent d55fab3 commit fa85371

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

testing/acceptance_test.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,37 @@ def test_func(tmpdir):
803803
result = testdir.runpytest(n)
804804
result.stdout.fnmatch_lines(["*UserWarning*foo.txt*", "*1 passed, 1 warnings*"])
805805

806+
@pytest.mark.parametrize("n", ["-n0", "-n1"])
807+
def test_unserializable_warning_details(self, testdir, n):
808+
"""Check that warnings with unserializable _WARNING_DETAILS are
809+
handled correctly (#379).
810+
"""
811+
testdir.makepyfile(
812+
"""
813+
import warnings, pytest
814+
import socket
815+
import gc
816+
def abuse_socket():
817+
s = socket.socket()
818+
del s
819+
820+
# Deliberately provoke a ResourceWarning for an unclosed socket.
821+
# The socket itself will end up attached as a value in
822+
# _WARNING_DETAIL. We need to test that it is not serialized
823+
# (it can't be, so the test will fail if we try to).
824+
def test_func(tmpdir):
825+
warnings.resetwarnings()
826+
warnings.simplefilter('always', ResourceWarning)
827+
abuse_socket()
828+
gc.collect()
829+
"""
830+
)
831+
testdir.syspathinsert()
832+
result = testdir.runpytest(n)
833+
result.stdout.fnmatch_lines(
834+
["*ResourceWarning*unclosed*", "*1 passed, 1 warnings*"]
835+
)
836+
806837

807838
class TestNodeFailure:
808839
def test_load_single(self, testdir):

0 commit comments

Comments
 (0)