A Hypothesis database, for use in |settings.database|. Hypothesis automatically saves failures to the database set in |settings.database|. The next time the test is run, Hypothesis will replay any failures from the database in |settings.database| for that test (in |Phase.reuse|
| 170 | |
| 171 | |
| 172 | class ExampleDatabase(metaclass=_EDMeta): |
| 173 | """ |
| 174 | A Hypothesis database, for use in |settings.database|. |
| 175 | |
| 176 | Hypothesis automatically saves failures to the database set in |
| 177 | |settings.database|. The next time the test is run, Hypothesis will replay |
| 178 | any failures from the database in |settings.database| for that test (in |
| 179 | |Phase.reuse|). |
| 180 | |
| 181 | The database is best thought of as a cache that you never need to invalidate. |
| 182 | Entries may be transparently dropped when upgrading your Hypothesis version |
| 183 | or changing your test. Do not rely on the database for correctness; to ensure |
| 184 | Hypothesis always tries an input, use |@example|. |
| 185 | |
| 186 | A Hypothesis database is a simple mapping of bytes to sets of bytes. Hypothesis |
| 187 | provides several concrete database subclasses. To write your own database class, |
| 188 | see :doc:`/how-to/custom-database`. |
| 189 | |
| 190 | Change listening |
| 191 | ---------------- |
| 192 | |
| 193 | An optional extension to |ExampleDatabase| is change listening. On databases |
| 194 | which support change listening, calling |ExampleDatabase.add_listener| adds |
| 195 | a function as a change listener, which will be called whenever a value is |
| 196 | added, deleted, or moved inside the database. See |ExampleDatabase.add_listener| |
| 197 | for details. |
| 198 | |
| 199 | All databases in Hypothesis support change listening. Custom database classes |
| 200 | are not required to support change listening, though they will not be compatible |
| 201 | with features that require change listening until they do so. |
| 202 | |
| 203 | .. note:: |
| 204 | |
| 205 | While no Hypothesis features currently require change listening, change |
| 206 | listening is required by `HypoFuzz <https://hypofuzz.com/>`_. |
| 207 | |
| 208 | Database methods |
| 209 | ---------------- |
| 210 | |
| 211 | Required methods: |
| 212 | |
| 213 | * |ExampleDatabase.save| |
| 214 | * |ExampleDatabase.fetch| |
| 215 | * |ExampleDatabase.delete| |
| 216 | |
| 217 | Optional methods: |
| 218 | |
| 219 | * |ExampleDatabase.move| |
| 220 | |
| 221 | Change listening methods: |
| 222 | |
| 223 | * |ExampleDatabase.add_listener| |
| 224 | * |ExampleDatabase.remove_listener| |
| 225 | * |ExampleDatabase.clear_listeners| |
| 226 | * |ExampleDatabase._start_listening| |
| 227 | * |ExampleDatabase._stop_listening| |
| 228 | * |ExampleDatabase._broadcast_change| |
| 229 | """ |
no outgoing calls