Debian Codegraph @

hypothesis-python/tests/cover/test_debug_information.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 re
12
13 import pytest
14
15 from hypothesis import Verbosity, given, settings, strategies as st
16 from hypothesis.database import InMemoryExampleDatabase
17
18 from tests.common.utils import capture_out
19
20
21 def test_reports_passes():
22 @given(st.integers())
23 @settings(
24 verbosity=Verbosity.debug, max_examples=1000, database=InMemoryExampleDatabase()
25 )
26 def test(i):
27 assert i < 10
28
29 with capture_out() as out, pytest.raises(AssertionError):
30 test()
31
32 value = out.getvalue()
33
34 assert "minimize_individual_choices" in value
35 assert "calls" in value
36 assert "shrinks" in value
37
38 shrinks_info = re.compile(r"call(s?) of which ([0-9]+) shrank")
39
40 for l in value.splitlines():
41 m = shrinks_info.search(l)
42 if m is not None and int(m.group(2)) != 0:
43 break
44 else:
45 pytest.xfail(reason="Sometimes the first failure is 10, and cannot shrink.")