Repository: HypothesisWorks/hypothesis

Issue:
Failed assertion when verbosity is `quiet`
Code:

```python
import hypothesis
import hypothesis.strategies

@hypothesis.example(None)
@hypothesis.settings(verbosity=hypothesis.Verbosity.quiet)
@hypothesis.given(hypothesis.strategies.integers())
def f(a):
    pass

f()
```

Failure:

```python
Traceback (most recent call last):
  File "tmp.py", line 10, in <module>
    f()
  File "tmp.py", line 5, in f
    @hypothesis.settings(verbosity=hypothesis.Verbosity.quiet)
  File "/home/gram/.local/lib/python3.8/site-packages/hypothesis/core.py", line 1090, in wrapped_test
    errors = list(
  File "/home/gram/.local/lib/python3.8/site-packages/hypothesis/core.py", line 379, in execute_explicit_examples
    assert fragments_reported[0].startswith("Falsifying example")
IndexError: list index out of range
```

Reason: `execute_explicit_examples` assumes that there are `fragments_reported` but there are always none if the `verbosity` is `quiet`.


Discussion:

Resolving patch:
diff --git a/hypothesis-python/src/hypothesis/core.py b/hypothesis-python/src/hypothesis/core.py
--- a/hypothesis-python/src/hypothesis/core.py
+++ b/hypothesis-python/src/hypothesis/core.py
@@ -376,14 +376,16 @@ def execute_explicit_examples(state, wrapped_test, arguments, kwargs):
                     continue
                 break
             finally:
-                assert fragments_reported[0].startswith("Falsifying example")
-                fragments_reported[0] = fragments_reported[0].replace(
-                    "Falsifying example", "Falsifying explicit example", 1
-                )
+                if fragments_reported:
+                    assert fragments_reported[0].startswith("Falsifying example")
+                    fragments_reported[0] = fragments_reported[0].replace(
+                        "Falsifying example", "Falsifying explicit example", 1
+                    )
 
-            verbose_report(fragments_reported[0].replace("Falsifying", "Trying", 1))
-            for f in fragments_reported[1:]:
-                verbose_report(f)
+            if fragments_reported:
+                verbose_report(fragments_reported[0].replace("Falsifying", "Trying", 1))
+                for f in fragments_reported[1:]:
+                    verbose_report(f)
 
 
 def get_random_for_wrapped_test(test, wrapped_test):


Test patch:
diff --git a/hypothesis-python/tests/cover/test_verbosity.py b/hypothesis-python/tests/cover/test_verbosity.py
--- a/hypothesis-python/tests/cover/test_verbosity.py
+++ b/hypothesis-python/tests/cover/test_verbosity.py
@@ -15,7 +15,7 @@
 
 from contextlib import contextmanager
 
-from hypothesis import find, given
+from hypothesis import example, find, given
 from hypothesis._settings import Verbosity, settings
 from hypothesis.reporting import default as default_reporter, with_reporter
 from hypothesis.strategies import booleans, integers, lists
@@ -110,3 +110,28 @@ def test_foo(x):
     lines = o.getvalue().splitlines()
     assert len([l for l in lines if "example" in l]) > 2
     assert [l for l in lines if "AssertionError" in l]
+
+
+@example(0)
+@settings(verbosity=Verbosity.quiet)
+@given(integers())
+def test_no_indexerror_in_quiet_mode(x):
+    # Regression tests for https://github.com/HypothesisWorks/hypothesis/issues/2696
+    # where quiet mode -> no fragments to report -> IndexError accessing first report
+    pass
+
+
+@fails
+@example(0)
+@settings(verbosity=Verbosity.quiet, report_multiple_bugs=True)
+@given(integers())
+def test_no_indexerror_in_quiet_mode_report_multiple(x):
+    assert x
+
+
+@fails
+@example(0)
+@settings(verbosity=Verbosity.quiet, report_multiple_bugs=False)
+@given(integers())
+def test_no_indexerror_in_quiet_mode_report_one(x):
+    assert x