From 4a15982c5aca2dfb969d51a65e5ecf9a6f28a92f Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Sat, 29 Sep 2018 12:26:45 -0300 Subject: [PATCH] WIP add test for #349 --- testing/acceptance_test.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index 987dbe61..d580623f 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -430,7 +430,7 @@ def test_func(request): result.stdout.fnmatch_lines(["*this is a warning*", "*1 passed, 1 warnings*"]) @pytest.mark.parametrize("n", ["-n0", "-n1"]) - def test_custom_subclass(self, testdir, n): + def test_custom_warning_subclass(self, testdir, n): """Check that warning subclasses that don't honor the args attribute don't break pytest-xdist (#344) """ @@ -458,6 +458,27 @@ def test_func(request): result = testdir.runpytest(n) result.stdout.fnmatch_lines(["*MyWarning*", "*1 passed, 1 warnings*"]) + @pytest.mark.parametrize("n", ["-n0", "-n1"]) + def test_warning_unserializable_arg(self, testdir, n): + """Check that warning with args that can't be serialized don't choke xdist (#349)""" + from pkg_resources import parse_version + + if parse_version(pytest.__version__) < parse_version("3.1"): + pytest.skip("pytest warnings requires >= 3.1") + + testdir.makepyfile( + """ + import warnings + + def test_func(tmpdir): + with open(str(tmpdir / 'foo.txt'), 'w') as f: + warnings.warn(UserWarning(f)) + """ + ) + testdir.syspathinsert() + result = testdir.runpytest(n) + result.stdout.fnmatch_lines(["*UserWarning*foo.txt*", "*1 passed, 1 warnings*"]) + def test_logfinish_hook(self, testdir): """Ensure the pytest_runtest_logfinish hook is being properly handled""" from _pytest import hookspec