Repository: HypothesisWorks/hypothesis

Issue:
Config option to skip pytest_report_header
With pytest's tests I am seeing the following line all the time.
I think it would be nice if it could be disabled (made quiet):

> hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('/home/user/Vcs/pytest/.hypothesis/examples')

There's `--hypothesis-verbosity` already, but it appears to have a different purpose?

I think a config/ini option would be good (instead of a cli argument/param).


Discussion:
Hmm, maybe we could have it disabled by default, but show it if either the pytest or Hypothesis verbosity was set at above default?

https://github.com/HypothesisWorks/hypothesis/blob/50c059c38c693d15f32eb9d928b7a6be3814579d/hypothesis-python/src/hypothesis/extra/pytestplugin.py#L74-L81
That would be a good start / compromise I think.
Could use "verbosity > 1", i.e. with `-vv` then only maybe.
(Note that I'm not sure how useful that information is in general, and would not have hypothesis installed by default in pytest probably, since it does not appear to get used still really)

Ref: https://github.com/pytest-dev/pytest/issues/4977#issuecomment-547293026

Resolving patch:
diff --git a/hypothesis-python/src/hypothesis/extra/pytestplugin.py b/hypothesis-python/src/hypothesis/extra/pytestplugin.py
--- a/hypothesis-python/src/hypothesis/extra/pytestplugin.py
+++ b/hypothesis-python/src/hypothesis/extra/pytestplugin.py
@@ -22,7 +22,7 @@
 import pytest
 
 from hypothesis import Verbosity, core, settings
-from hypothesis._settings import note_deprecation
+from hypothesis._settings import Verbosity, note_deprecation
 from hypothesis.errors import InvalidArgument
 from hypothesis.internal.compat import OrderedDict, text_type
 from hypothesis.internal.detection import is_hypothesis_test
@@ -79,7 +79,8 @@ def pytest_report_header(config):
     settings_str = settings.get_profile(profile).show_changed()
     if settings_str != "":
         settings_str = " -> %s" % (settings_str)
-    return "hypothesis profile %r%s" % (profile, settings_str)
+    if config.option.verbose >= 1 or settings.default.verbosity >= Verbosity.verbose:
+        return "hypothesis profile %r%s" % (profile, settings_str)
 
 
 def pytest_configure(config):


Test patch:
diff --git a/hypothesis-python/tests/cover/test_setup_teardown.py b/hypothesis-python/tests/cover/test_setup_teardown.py
--- a/hypothesis-python/tests/cover/test_setup_teardown.py
+++ b/hypothesis-python/tests/cover/test_setup_teardown.py
@@ -19,7 +19,7 @@
 
 import pytest
 
-from hypothesis import assume, given
+from hypothesis import assume, given, settings
 from hypothesis.strategies import integers, text
 
 
@@ -45,6 +45,7 @@ def give_me_a_string(myself, x):
         pass
 
     @given(integers())
+    @settings(max_examples=1000)
     def give_me_a_positive_int(self, x):
         assert x >= 0
 
diff --git a/hypothesis-python/tests/pytest/test_profiles.py b/hypothesis-python/tests/pytest/test_profiles.py
--- a/hypothesis-python/tests/pytest/test_profiles.py
+++ b/hypothesis-python/tests/pytest/test_profiles.py
@@ -17,6 +17,8 @@
 
 from __future__ import absolute_import, division, print_function
 
+import pytest
+
 from hypothesis.extra.pytestplugin import LOAD_PROFILE_OPTION
 from hypothesis.version import __version__
 
@@ -37,11 +39,23 @@ def test_this_one_is_ok():
 """
 
 
-def test_runs_reporting_hook(testdir):
+def test_does_not_run_reporting_hook_by_default(testdir):
     script = testdir.makepyfile(TESTSUITE)
     testdir.makeconftest(CONFTEST)
     result = testdir.runpytest(script, LOAD_PROFILE_OPTION, "test")
     out = "\n".join(result.stdout.lines)
     assert "1 passed" in out
+    assert "hypothesis profile" not in out
+    assert __version__ in out
+
+
+@pytest.mark.parametrize("option", ["-v", "--hypothesis-verbosity=verbose"])
+def test_runs_reporting_hook_in_any_verbose_mode(testdir, option):
+    script = testdir.makepyfile(TESTSUITE)
+    testdir.makeconftest(CONFTEST)
+    result = testdir.runpytest(script, LOAD_PROFILE_OPTION, "test", option)
+    out = "\n".join(result.stdout.lines)
+    assert "1 passed" in out
     assert "max_examples=1" in out
+    assert "hypothesis profile" in out
     assert __version__ in out