Repository: HypothesisWorks/hypothesis

Issue:
Omit sqlite database implementation when sqlite is not available
Some platforms ship the sqlite library separately from core Python (bsd) or don't implement it at all (Jython). This is annoying, because it means Hypothesis doesn't work because it tries to import sqlite3.

This is particularly annoying these days because we don't even really *need* the sqlite implementation.

We could either check for availability and not provide that implementation in that case, or we could just deprecate the silly thing and move on.


Discussion:
[The database docs](https://hypothesis.readthedocs.io/en/latest/database.html) suggest that this has been implemented, and that the sqlite3 option may even be removed in future.  If this is not the case, I think we have a docs bug instead.
So this has been implemented in the sense that we now don't use sqlite by default, but we still import it unconditionally so things will still break if you don't have it. I'll update the ticket accordingly.
It actually looks like it'll be a pretty easy fix to `database.py`, plus some corrections to documentation (including docstrings for settings; do a whole-project search).  

Will we want to start running on Jython in CI?
> Will we want to start running on Jython in CI?

Jython support is substantially more complicated than just this one thing, and TBH I'm not sure it's worth it. If someone wants to put in the work to make Hypothesis work on Jython we could certainly start running it in CI, but I'm not sure there's a good reason to.

Resolving patch:
diff --git a/src/hypothesis/_settings.py b/src/hypothesis/_settings.py
--- a/src/hypothesis/_settings.py
+++ b/src/hypothesis/_settings.py
@@ -246,8 +246,8 @@ def database(self):
         If this was explicitly set at settings instantiation then that
         value will be used (even if it was None). If not and the
         database_file setting is not None this will be lazily loaded as
-        an SQLite backed ExampleDatabase using that file the first time
-        this property is accessed on a particular thread.
+        an ExampleDatabase using that file the first time this property
+        is accessed on a particular thread.
 
         """
         if self._database is not_set and self.database_file is not None:
diff --git a/src/hypothesis/database.py b/src/hypothesis/database.py
--- a/src/hypothesis/database.py
+++ b/src/hypothesis/database.py
@@ -19,7 +19,6 @@
 
 import os
 import re
-import sqlite3
 import binascii
 import threading
 from contextlib import contextmanager
@@ -27,6 +26,7 @@
 from hypothesis.internal.compat import FileNotFoundError, sha1, \
     b64decode, b64encode
 
+sqlite3 = None
 SQLITE_PATH = re.compile(r"\.\(db|sqlite|sqlite3\)$")
 
 
@@ -115,6 +115,8 @@ def __init__(self, path=u':memory:'):
         self.path = path
         self.db_created = False
         self.current_connection = threading.local()
+        global sqlite3
+        import sqlite3
 
     def connection(self):
         if not hasattr(self.current_connection, 'connection'):
diff --git a/src/hypothesis/version.py b/src/hypothesis/version.py
--- a/src/hypothesis/version.py
+++ b/src/hypothesis/version.py
@@ -17,5 +17,5 @@
 
 from __future__ import division, print_function, absolute_import
 
-__version_info__ = (3, 8, 4)
+__version_info__ = (3, 8, 5)
 __version__ = '.'.join(map(str, __version_info__))


Test patch: