Repository: HypothesisWorks/hypothesis

Issue:
Ensure compatibility with Django 2.2 and run it in CI
[Django 2.2 has just been released](https://www.djangoproject.com/weblog/2019/apr/01/django-22-released/), which means we should start running against it in CI and add it to the list of supported versions in documentation.

That should be fairly simple, since most of the incompatible changes seem to be for third-party databases.  However we [have this test failure](https://dev.azure.com/HypothesisWorks/Hypothesis/_build/results?buildId=1880&view=logs&jobId=70e7c352-5680-5004-a987-5b5fc78e2b1a&taskId=36365705-09d6-5cbf-fdf3-d70278821097&lineStart=554&lineEnd=555&colStart=1&colEnd=1), which I think is because our example/test project is older than some current best practices.
Derandomize some expected-failure tests to work around #1907
While I haven't figured out the precise cause of #1907, this workaround should at least prevent it from blocking all other work.


Discussion:

Resolving patch:
diff --git a/tooling/src/hypothesistooling/__main__.py b/tooling/src/hypothesistooling/__main__.py
--- a/tooling/src/hypothesistooling/__main__.py
+++ b/tooling/src/hypothesistooling/__main__.py
@@ -443,10 +443,9 @@ def standard_tox_task(name):
 
 standard_tox_task("nose")
 standard_tox_task("pytest30")
-standard_tox_task("django21")
-standard_tox_task("django20")
-standard_tox_task("django111")
 
+for n in [20, 21, 22, 111]:
+    standard_tox_task("django%d" % (n,))
 for n in [19, 20, 21, 22, 23, 24]:
     standard_tox_task("pandas%d" % (n,))
 


Test patch:
diff --git a/hypothesis-python/tests/cover/test_stateful.py b/hypothesis-python/tests/cover/test_stateful.py
--- a/hypothesis-python/tests/cover/test_stateful.py
+++ b/hypothesis-python/tests/cover/test_stateful.py
@@ -795,6 +795,7 @@ def test_removes_needless_steps():
     but will still fail with very high probability.
     """
 
+    @Settings(derandomize=True)
     class IncorrectDeletion(RuleBasedStateMachine):
         def __init__(self):
             super(IncorrectDeletion, self).__init__()
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
@@ -100,7 +100,7 @@ def test_includes_intermediate_results_in_verbose_mode():
     with capture_verbosity() as o:
 
         @fails
-        @settings(verbosity=Verbosity.verbose, database=None)
+        @settings(verbosity=Verbosity.verbose, database=None, derandomize=True)
         @given(lists(integers(), min_size=1))
         def test_foo(x):
             assert sum(x) < 1000000
diff --git a/hypothesis-python/tests/django/toys/settings.py b/hypothesis-python/tests/django/toys/settings.py
--- a/hypothesis-python/tests/django/toys/settings.py
+++ b/hypothesis-python/tests/django/toys/settings.py
@@ -102,3 +102,30 @@
 # https://docs.djangoproject.com/en/1.7/howto/static-files/
 
 STATIC_URL = u"/static/"
+
+
+# Added these bits to avoid warnings on Django 2.2
+
+TEMPLATES = [
+    {
+        "BACKEND": "django.template.backends.django.DjangoTemplates",
+        "OPTIONS": {
+            "context_processors": [
+                "django.template.context_processors.debug",
+                "django.template.context_processors.request",
+                "django.contrib.auth.context_processors.auth",
+                "django.contrib.messages.context_processors.messages",
+            ]
+        },
+    }
+]
+
+MIDDLEWARE = [
+    "django.middleware.security.SecurityMiddleware",
+    "django.contrib.sessions.middleware.SessionMiddleware",
+    "django.middleware.common.CommonMiddleware",
+    "django.middleware.csrf.CsrfViewMiddleware",
+    "django.contrib.auth.middleware.AuthenticationMiddleware",
+    "django.contrib.messages.middleware.MessageMiddleware",
+    "django.middleware.clickjacking.XFrameOptionsMiddleware",
+]
diff --git a/hypothesis-python/tests/django/toystore/test_basic_configuration.py b/hypothesis-python/tests/django/toystore/test_basic_configuration.py
--- a/hypothesis-python/tests/django/toystore/test_basic_configuration.py
+++ b/hypothesis-python/tests/django/toystore/test_basic_configuration.py
@@ -23,7 +23,7 @@
 from django.db import IntegrityError
 from django.test import TestCase as DjangoTestCase
 
-from hypothesis import HealthCheck, given, settings
+from hypothesis import HealthCheck, Verbosity, given, settings
 from hypothesis.errors import InvalidArgument
 from hypothesis.extra.django import TestCase, TransactionTestCase
 from hypothesis.internal.compat import PYPY
@@ -64,7 +64,9 @@ def break_the_db(i):
 
         class LocalTest(TestCase):
             @given(integers().map(break_the_db))
-            @settings(suppress_health_check=HealthCheck.all())
+            @settings(
+                suppress_health_check=HealthCheck.all(), verbosity=Verbosity.quiet
+            )
             def test_does_not_break_other_things(self, unused):
                 pass