Debian Codegraph @

hypothesis-python/tests/pytest/test_reporting.py

raw
1 # This file is part of Hypothesis, which may be found at
2 # https://github.com/HypothesisWorks/hypothesis/
3 #
4 # Copyright the Hypothesis Authors.
5 # Individual contributors are listed in AUTHORS.rst and the git log.
6 #
7 # This Source Code Form is subject to the terms of the Mozilla Public License,
8 # v. 2.0. If a copy of the MPL was not distributed with this file, You can
9 # obtain one at https://mozilla.org/MPL/2.0/.
10
11 import pytest
12
13 pytest_plugins = "pytester"
14
15
16 TESTSUITE = """
17 from hypothesis import given
18 from hypothesis.strategies import lists, integers
19
20 @given(integers())
21 def test_this_one_is_ok(x):
22 pass
23
24 @given(lists(integers()))
25 def test_hi(xs):
26 assert False
27 """
28
29
30 def test_runs_reporting_hook(testdir):
31 script = testdir.makepyfile(TESTSUITE)
32 result = testdir.runpytest(script, "--verbose")
33 out = "\n".join(result.stdout.lines)
34 assert "test_this_one_is_ok" in out
35 assert "Captured stdout call" not in out
36 assert "Falsifying example" in out
37 assert result.ret != 0
38
39
40 TEST_EXCEPTIONGROUP = """
41 from hypothesis import given, strategies as st
42
43 @given(x=st.booleans())
44 def test_fuzz_sorted(x):
45 raise ValueError if x else TypeError
46 """
47
48
49 @pytest.mark.parametrize("tb", ["auto", "long", "short", "native"])
50 def test_no_missing_reports(testdir, tb):
51 script = testdir.makepyfile(TEST_EXCEPTIONGROUP)
52 result = testdir.runpytest(script, f"--tb={tb}")
53 out = "\n".join(result.stdout.lines)
54 # If the False case is missing, that means we're not printing exception info.
55 # See https://github.com/HypothesisWorks/hypothesis/issues/3430 With --tb=native,
56 # we should show the full ExceptionGroup with *both* errors.
57 assert "x=False" in out
58 assert "x=True" in out or tb != "native"