Debian Codegraph @

hypothesis-python/tests/cover/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 os
12 import sys
13
14 import pytest
15
16 from hypothesis import given, reporting
17 from hypothesis._settings import Verbosity, settings
18 from hypothesis.reporting import debug_report, verbose_report
19 from hypothesis.strategies import integers
20
21 from tests.common.utils import capture_out
22
23
24 def test_prints_output_by_default():
25 @given(integers())
26 def test_int(x):
27 raise AssertionError
28
29 with pytest.raises(AssertionError) as err:
30 test_int()
31 assert "Falsifying example" in "\n".join(err.value.__notes__)
32
33
34 def test_does_not_print_debug_in_verbose():
35 @given(integers())
36 @settings(verbosity=Verbosity.verbose)
37 def f(x):
38 debug_report("Hi")
39
40 with capture_out() as o:
41 f()
42 assert "Hi" not in o.getvalue()
43
44
45 def test_does_print_debug_in_debug():
46 @given(integers())
47 @settings(verbosity=Verbosity.debug)
48 def f(x):
49 debug_report("Hi")
50
51 with capture_out() as o:
52 f()
53 assert "Hi" in o.getvalue()
54
55
56 def test_does_print_verbose_in_debug():
57 @given(integers())
58 @settings(verbosity=Verbosity.debug)
59 def f(x):
60 verbose_report("Hi")
61
62 with capture_out() as o:
63 f()
64 assert "Hi" in o.getvalue()
65
66
67 def test_can_report_when_system_locale_is_ascii(monkeypatch):
68 read, write = os.pipe()
69 with (
70 open(read, encoding="ascii") as read,
71 open(write, "w", encoding="ascii") as write,
72 ):
73 monkeypatch.setattr(sys, "stdout", write)
74 reporting.default("☃")