Debian Codegraph @

hypothesis-python/tests/pytest/test_profiles.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 importlib
12
13 import pytest
14 from _hypothesis_pytestplugin import LOAD_PROFILE_OPTION
15
16 pytest_plugins = "pytester"
17
18
19 CONFTEST = """
20 from hypothesis._settings import settings
21 settings.register_profile("test", settings(max_examples=1))
22 """
23
24 TESTSUITE = """
25 from hypothesis import given
26 from hypothesis.strategies import integers
27 from hypothesis._settings import settings
28
29 def test_this_one_is_ok():
30 assert settings().max_examples == 1
31 """
32
33
34 def test_does_not_run_reporting_hook_by_default(testdir):
35 script = testdir.makepyfile(TESTSUITE)
36 testdir.makeconftest(CONFTEST)
37 result = testdir.runpytest(script, LOAD_PROFILE_OPTION, "test")
38 out = "\n".join(result.stdout.lines)
39 assert "1 passed" in out
40 assert "hypothesis profile" not in out
41 # importlib.metadata.version respects e.g. local -e installs of hypothesis,
42 # and matches what `pytest` uses more closely than `hypothesis.__version__`
43 # (which is the actually-latest version).
44 assert importlib.metadata.version("hypothesis") in out
45
46
47 @pytest.mark.parametrize("option", ["-v", "--hypothesis-verbosity=verbose"])
48 def test_runs_reporting_hook_in_any_verbose_mode(testdir, option):
49 script = testdir.makepyfile(TESTSUITE)
50 testdir.makeconftest(CONFTEST)
51 result = testdir.runpytest(script, LOAD_PROFILE_OPTION, "test", option)
52 out = "\n".join(result.stdout.lines)
53 assert "1 passed" in out
54 assert "max_examples=1" in out
55 assert "hypothesis profile" in out
56 assert importlib.metadata.version("hypothesis") in out