Repository: HypothesisWorks/hypothesis

Issue:
[Pytest integration] Log the settings and profile name that are globally in effect (or make this easier for users)
When I run my test suite using pytest, other pytest plugins in use such as pytest-benchmark helpfully log the settings that they have globally in effect:
```
platform darwin -- Python 3.6.5, pytest-3.5.0, py-1.5.3, pluggy-0.6.0 -- /usr/local/opt/python/bin/python3.6
cachedir: .pytest_cache
benchmark: 3.1.1 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=False warmup_iterations=100000)
...
```
Can Hypothesis do something similar, or at least make it easier for users to do this? Otherwise dealing with captured output in pytest can be tricky and annoying, and there's also no public API for querying for the currently-active profile (only the private `hypothesis.settings._current_profile`).


Discussion:
Related to #1238.
Gonna take a look at this.

Resolving patch:
diff --git a/hypothesis-python/src/hypothesis/_settings.py b/hypothesis-python/src/hypothesis/_settings.py
--- a/hypothesis-python/src/hypothesis/_settings.py
+++ b/hypothesis-python/src/hypothesis/_settings.py
@@ -317,10 +317,20 @@ def __repr__(self):
         bits = []
         for name, setting in all_settings.items():
             value = getattr(self, name)
+            # The only settings that are not shown are those that are
+            # deprecated and left at their default values.
             if value != setting.default or not setting.hide_repr:
                 bits.append('%s=%r' % (name, value))
         return 'settings(%s)' % ', '.join(sorted(bits))
 
+    def show_changed(self):
+        bits = []
+        for name, setting in all_settings.items():
+            value = getattr(self, name)
+            if value != setting.default:
+                bits.append('%s=%r' % (name, value))
+        return ', '.join(sorted(bits, key=len))
+
     def __enter__(self):
         note_deprecation(
             'Settings should be determined only by global state or with the '
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
@@ -19,7 +19,7 @@
 
 import pytest
 
-import hypothesis.core as core
+from hypothesis import core, settings
 from hypothesis.reporting import default as default_reporter
 from hypothesis.reporting import with_reporter
 from hypothesis.statistics import collector
@@ -65,9 +65,18 @@ def pytest_addoption(parser):
     )
 
 
+def pytest_report_header(config):
+    profile = config.getoption(LOAD_PROFILE_OPTION)
+    if not profile:
+        profile = 'default'
+    settings_str = settings.get_profile(profile).show_changed()
+    if settings_str != '':
+        settings_str = ' -> %s' % (settings_str)
+    return 'hypothesis profile %r%s' % (profile, settings_str)
+
+
 def pytest_configure(config):
     core.running_under_pytest = True
-    from hypothesis import settings
     profile = config.getoption(LOAD_PROFILE_OPTION)
     if profile:
         settings.load_profile(profile)


Test patch:
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,7 @@
 
 from __future__ import division, print_function, absolute_import
 
+from hypothesis.version import __version__
 from hypothesis.extra.pytestplugin import LOAD_PROFILE_OPTION
 
 pytest_plugins = str('pytester')
@@ -42,3 +43,5 @@ def test_runs_reporting_hook(testdir):
     result = testdir.runpytest(script, LOAD_PROFILE_OPTION, 'test')
     out = '\n'.join(result.stdout.lines)
     assert '1 passed' in out
+    assert 'max_examples=1' in out
+    assert __version__ in out