Skip to content

Commit

Permalink
Merge pull request #2165 from Zac-HD/quiet-pytest
Browse files Browse the repository at this point in the history
Only add profile info to pytest header if in verbose mode
  • Loading branch information
Zac-HD committed Nov 2, 2019
2 parents 10b6a8b + 44416e2 commit f857eca
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
6 changes: 6 additions & 0 deletions hypothesis-python/RELEASE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
RELEASE_TYPE: patch

This patch ensures that we only add profile information to the pytest header
if running either pytest or Hypothesis in verbose mode, matching the
`builtin cache plugin <https://docs.pytest.org/en/latest/cache.html>`__
(:issue:`2155`).
5 changes: 3 additions & 2 deletions hypothesis-python/src/hypothesis/extra/pytestplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion hypothesis-python/tests/cover/test_setup_teardown.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import pytest

from hypothesis import assume, given
from hypothesis import assume, given, settings
from hypothesis.strategies import integers, text


Expand All @@ -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

Expand Down
16 changes: 15 additions & 1 deletion hypothesis-python/tests/pytest/test_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__

Expand All @@ -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

0 comments on commit f857eca

Please sign in to comment.