/usr/share/doc/python-hypothesis/html/settings.html is in python-hypothesis-doc 3.44.1-2ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 | <!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Settings — Hypothesis 3.44.1 documentation</title>
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<link rel="index" title="Index"
href="genindex.html"/>
<link rel="search" title="Search" href="search.html"/>
<link rel="top" title="Hypothesis 3.44.1 documentation" href="index.html"/>
<link rel="next" title="What you can generate and how" href="data.html"/>
<link rel="prev" title="Details and advanced features" href="details.html"/>
<script src="_static/js/modernizr.min.js"></script>
</head>
<body class="wy-body-for-nav" role="document">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search">
<a href="index.html" class="icon icon-home"> Hypothesis
</a>
<div class="version">
3.44.1
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="quickstart.html">Quick start guide</a></li>
<li class="toctree-l1"><a class="reference internal" href="details.html">Details and advanced features</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">Settings</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#module-hypothesis">Available settings</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#controlling-what-runs">Controlling What Runs</a></li>
<li class="toctree-l3"><a class="reference internal" href="#seeing-intermediate-result">Seeing intermediate result</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="#building-settings-objects">Building settings objects</a></li>
<li class="toctree-l2"><a class="reference internal" href="#default-settings">Default settings</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#settings-profiles">settings Profiles</a></li>
<li class="toctree-l3"><a class="reference internal" href="#timeouts">Timeouts</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="data.html">What you can generate and how</a></li>
<li class="toctree-l1"><a class="reference internal" href="extras.html">Additional packages</a></li>
<li class="toctree-l1"><a class="reference internal" href="django.html">Hypothesis for Django users</a></li>
<li class="toctree-l1"><a class="reference internal" href="numpy.html">Hypothesis for the Scientific Stack</a></li>
<li class="toctree-l1"><a class="reference internal" href="healthchecks.html">Health checks</a></li>
<li class="toctree-l1"><a class="reference internal" href="database.html">The Hypothesis Example Database</a></li>
<li class="toctree-l1"><a class="reference internal" href="stateful.html">Stateful testing</a></li>
<li class="toctree-l1"><a class="reference internal" href="supported.html">Compatibility</a></li>
<li class="toctree-l1"><a class="reference internal" href="examples.html">Some more examples</a></li>
<li class="toctree-l1"><a class="reference internal" href="community.html">Community</a></li>
<li class="toctree-l1"><a class="reference internal" href="manifesto.html">The Purpose of Hypothesis</a></li>
<li class="toctree-l1"><a class="reference internal" href="endorsements.html">Testimonials</a></li>
<li class="toctree-l1"><a class="reference internal" href="usage.html">Open Source Projects using Hypothesis</a></li>
<li class="toctree-l1"><a class="reference internal" href="strategies.html">Projects extending Hypothesis</a></li>
<li class="toctree-l1"><a class="reference internal" href="changes.html">Changelog</a></li>
<li class="toctree-l1"><a class="reference internal" href="development.html">Ongoing Hypothesis Development</a></li>
<li class="toctree-l1"><a class="reference internal" href="support.html">Help and Support</a></li>
<li class="toctree-l1"><a class="reference internal" href="packaging.html">Packaging Guidelines</a></li>
<li class="toctree-l1"><a class="reference internal" href="reproducing.html">Reproducing Failures</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" role="navigation" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="index.html">Hypothesis</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="index.html">Docs</a> »</li>
<li>Settings</li>
<li class="wy-breadcrumbs-aside">
<a href="_sources/settings.rst.txt" rel="nofollow"> View page source</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<div class="section" id="settings">
<h1>Settings<a class="headerlink" href="#settings" title="Permalink to this headline">¶</a></h1>
<p>Hypothesis tries to have good defaults for its behaviour, but sometimes that’s
not enough and you need to tweak it.</p>
<p>The mechanism for doing this is the <a class="reference internal" href="#hypothesis.settings" title="hypothesis.settings"><code class="xref py py-class docutils literal"><span class="pre">settings</span></code></a> object.
You can set up a <a class="reference internal" href="details.html#hypothesis.given" title="hypothesis.given"><code class="xref py py-func docutils literal"><span class="pre">@given</span></code></a> based test to use this using a settings
decorator:</p>
<p><a class="reference internal" href="details.html#hypothesis.given" title="hypothesis.given"><code class="xref py py-func docutils literal"><span class="pre">@given</span></code></a> invocation is as follows:</p>
<div class="code python highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">hypothesis</span> <span class="k">import</span> <span class="n">given</span><span class="p">,</span> <span class="n">settings</span>
<span class="nd">@given</span><span class="p">(</span><span class="n">integers</span><span class="p">())</span>
<span class="nd">@settings</span><span class="p">(</span><span class="n">max_examples</span><span class="o">=</span><span class="mi">500</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">test_this_thoroughly</span><span class="p">(</span><span class="n">x</span><span class="p">):</span>
<span class="k">pass</span>
</pre></div>
</div>
<p>This uses a <a class="reference internal" href="#hypothesis.settings" title="hypothesis.settings"><code class="xref py py-class docutils literal"><span class="pre">settings</span></code></a> object which causes the test to receive a much larger
set of examples than normal.</p>
<p>This may be applied either before or after the given and the results are
the same. The following is exactly equivalent:</p>
<div class="code python highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">hypothesis</span> <span class="k">import</span> <span class="n">given</span><span class="p">,</span> <span class="n">settings</span>
<span class="nd">@settings</span><span class="p">(</span><span class="n">max_examples</span><span class="o">=</span><span class="mi">500</span><span class="p">)</span>
<span class="nd">@given</span><span class="p">(</span><span class="n">integers</span><span class="p">())</span>
<span class="k">def</span> <span class="nf">test_this_thoroughly</span><span class="p">(</span><span class="n">x</span><span class="p">):</span>
<span class="k">pass</span>
</pre></div>
</div>
<div class="section" id="module-hypothesis">
<span id="available-settings"></span><h2>Available settings<a class="headerlink" href="#module-hypothesis" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="hypothesis.settings">
<em class="property">class </em><code class="descclassname">hypothesis.</code><code class="descname">settings</code><span class="sig-paren">(</span><em>parent=None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/hypothesis/_settings.html#settings"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#hypothesis.settings" title="Permalink to this definition">¶</a></dt>
<dd><p>A settings object controls a variety of parameters that are used in
falsification. These may control both the falsification strategy and the
details of the data that is generated.</p>
<p>Default values are picked up from the settings.default object and
changes made there will be picked up in newly created settings.</p>
<dl class="attribute">
<dt id="hypothesis.settings.database_file">
<code class="descname">database_file</code><a class="headerlink" href="#hypothesis.settings.database_file" title="Permalink to this definition">¶</a></dt>
<dd><p>An instance of hypothesis.database.ExampleDatabase that will be
used to save examples to and load previous examples from. May be None
in which case no storage will be used.</p>
<p>default value: (dynamically calculated)</p>
</dd></dl>
<dl class="attribute">
<dt id="hypothesis.settings.database">
<code class="descname">database</code><a class="headerlink" href="#hypothesis.settings.database" title="Permalink to this definition">¶</a></dt>
<dd><p>An ExampleDatabase instance to use for storage of examples. May be
None.</p>
<p>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 ExampleDatabase, using that file the first time that this
property is accessed on a particular thread.</p>
</dd></dl>
<dl class="attribute">
<dt id="hypothesis.settings.buffer_size">
<code class="descname">buffer_size</code><a class="headerlink" href="#hypothesis.settings.buffer_size" title="Permalink to this definition">¶</a></dt>
<dd><p>The size of the underlying data used to generate examples. If you need to
generate really large examples you may want to increase this, but it will make
your tests slower.</p>
<p>default value: 8192</p>
</dd></dl>
<dl class="attribute">
<dt id="hypothesis.settings.deadline">
<code class="descname">deadline</code><a class="headerlink" href="#hypothesis.settings.deadline" title="Permalink to this definition">¶</a></dt>
<dd><p>If set, a time in milliseconds (which may be a float to express
smaller units of time) that each individual example (i.e. each time your test
function is called, not the whole decorated test) within a test is not
allowed to exceed. Tests which take longer than that may be converted into
errors (but will not necessarily be if close to the deadline, to allow some
variability in test run time).</p>
<p>Set this to None to disable this behaviour entirely.</p>
<p>In future this will default to 200. For now, a
HypothesisDeprecationWarning will be emitted if you exceed that default
deadline and have not explicitly set a deadline yourself.</p>
<p>default value: not_set</p>
</dd></dl>
<dl class="attribute">
<dt id="hypothesis.settings.derandomize">
<code class="descname">derandomize</code><a class="headerlink" href="#hypothesis.settings.derandomize" title="Permalink to this definition">¶</a></dt>
<dd><p>If this is True then hypothesis will run in deterministic mode
where each falsification uses a random number generator that is seeded
based on the hypothesis to falsify, which will be consistent across
multiple runs. This has the advantage that it will eliminate any
randomness from your tests, which may be preferable for some situations.
It does have the disadvantage of making your tests less likely to
find novel breakages.</p>
<p>default value: False</p>
</dd></dl>
<dl class="attribute">
<dt id="hypothesis.settings.max_examples">
<code class="descname">max_examples</code><a class="headerlink" href="#hypothesis.settings.max_examples" title="Permalink to this definition">¶</a></dt>
<dd><p>Once this many satisfying examples have been considered without finding any
counter-example, falsification will terminate.</p>
<p>default value: 100</p>
</dd></dl>
<dl class="attribute">
<dt id="hypothesis.settings.max_iterations">
<code class="descname">max_iterations</code><a class="headerlink" href="#hypothesis.settings.max_iterations" title="Permalink to this definition">¶</a></dt>
<dd><p>Once this many iterations of the example loop have run, including ones which
failed to satisfy assumptions and ones which produced duplicates, falsification
will terminate.</p>
<p>default value: 1000</p>
</dd></dl>
<dl class="attribute">
<dt id="hypothesis.settings.max_shrinks">
<code class="descname">max_shrinks</code><a class="headerlink" href="#hypothesis.settings.max_shrinks" title="Permalink to this definition">¶</a></dt>
<dd><p>Once this many successful shrinks have been performed, Hypothesis will assume
something has gone a bit wrong and give up rather than continuing to try to
shrink the example.</p>
<p>default value: 500</p>
</dd></dl>
<dl class="attribute">
<dt id="hypothesis.settings.min_satisfying_examples">
<code class="descname">min_satisfying_examples</code><a class="headerlink" href="#hypothesis.settings.min_satisfying_examples" title="Permalink to this definition">¶</a></dt>
<dd><p>Raise Unsatisfiable for any tests which do not produce at least this many
values that pass all assume() calls and which have not exhaustively covered the
search space.</p>
<p>default value: 5</p>
</dd></dl>
<dl class="attribute">
<dt id="hypothesis.settings.perform_health_check">
<code class="descname">perform_health_check</code><a class="headerlink" href="#hypothesis.settings.perform_health_check" title="Permalink to this definition">¶</a></dt>
<dd><p>If set to True, Hypothesis will run a preliminary health check before
attempting to actually execute your test.</p>
<p>default value: True</p>
</dd></dl>
<dl class="attribute">
<dt id="hypothesis.settings.phases">
<code class="descname">phases</code><a class="headerlink" href="#hypothesis.settings.phases" title="Permalink to this definition">¶</a></dt>
<dd><p>Control which phases should be run. See <a class="reference internal" href="#phases"><span class="std std-ref">the full documentation for more details</span></a></p>
<p>default value: (<Phase.explicit: 0>, <Phase.reuse: 1>, <Phase.generate: 2>, <Phase.shrink: 3>)</p>
</dd></dl>
<dl class="attribute">
<dt id="hypothesis.settings.stateful_step_count">
<code class="descname">stateful_step_count</code><a class="headerlink" href="#hypothesis.settings.stateful_step_count" title="Permalink to this definition">¶</a></dt>
<dd><p>Number of steps to run a stateful program for before giving up on it breaking.</p>
<p>default value: 50</p>
</dd></dl>
<dl class="attribute">
<dt id="hypothesis.settings.strict">
<code class="descname">strict</code><a class="headerlink" href="#hypothesis.settings.strict" title="Permalink to this definition">¶</a></dt>
<dd><p>If set to True, anything that would cause Hypothesis to issue a warning will
instead raise an error. Note that new warnings may be added at any time, so
running with strict set to True means that new Hypothesis releases may validly
break your code. Note also that, as strict mode is itself deprecated,
enabling it is now an error!</p>
<p>You can enable this setting temporarily by setting the HYPOTHESIS_STRICT_MODE
environment variable to the string ‘true’.</p>
<p>default value: False</p>
<p>Strict mode is deprecated and will go away in a future version of Hypothesis.
To get the same behaviour, use
warnings.simplefilter(‘error’, HypothesisDeprecationWarning).</p>
</dd></dl>
<dl class="attribute">
<dt id="hypothesis.settings.suppress_health_check">
<code class="descname">suppress_health_check</code><a class="headerlink" href="#hypothesis.settings.suppress_health_check" title="Permalink to this definition">¶</a></dt>
<dd><p>A list of health checks to disable.</p>
<p>default value: ()</p>
</dd></dl>
<dl class="attribute">
<dt id="hypothesis.settings.timeout">
<code class="descname">timeout</code><a class="headerlink" href="#hypothesis.settings.timeout" title="Permalink to this definition">¶</a></dt>
<dd><p>Once this many seconds have passed, falsify will terminate even
if it has not found many examples. This is a soft rather than a hard
limit - Hypothesis won’t e.g. interrupt execution of the called
function to stop it. If this value is <= 0 then no timeout will be
applied.</p>
<p>default value: 60</p>
<p>The timeout setting is deprecated and will be removed in a future version of
Hypothesis. To get the future behaviour set <code class="docutils literal"><span class="pre">timeout=hypothesis.unlimited</span></code>
instead (which will remain valid for a further deprecation period after this
setting has gone away).</p>
</dd></dl>
<dl class="attribute">
<dt id="hypothesis.settings.use_coverage">
<code class="descname">use_coverage</code><a class="headerlink" href="#hypothesis.settings.use_coverage" title="Permalink to this definition">¶</a></dt>
<dd><p>Whether to use coverage information to improve Hypothesis’s ability to find
bugs.</p>
<p>You should generally leave this turned on unless your code performs
poorly when run under coverage. If you turn it off, please file a bug report
or add a comment to an existing one about the problem that prompted you to do
so.</p>
<p>default value: True</p>
</dd></dl>
</dd></dl>
<div class="section" id="controlling-what-runs">
<span id="phases"></span><h3>Controlling What Runs<a class="headerlink" href="#controlling-what-runs" title="Permalink to this headline">¶</a></h3>
<p>Hypothesis divides tests into four logically distinct phases:</p>
<ol class="arabic simple">
<li>Running explicit examples <a class="reference internal" href="reproducing.html#providing-explicit-examples"><span class="std std-ref">provided with the @example decorator</span></a>.</li>
<li>Rerunning a selection of previously failing examples to reproduce a previously seen error</li>
<li>Generating new examples.</li>
<li>Attempting to shrink an example found in phases 2 or 3 to a more manageable
one (explicit examples cannot be shrunk).</li>
</ol>
<p>The phases setting provides you with fine grained control over which of these run,
with each phase corresponding to a value on the <code class="xref py py-class docutils literal"><span class="pre">Phase</span></code> enum:</p>
<ol class="arabic simple">
<li><code class="docutils literal"><span class="pre">Phase.explicit</span></code> controls whether explicit examples are run.</li>
<li><code class="docutils literal"><span class="pre">Phase.reuse</span></code> controls whether previous examples will be reused.</li>
<li><code class="docutils literal"><span class="pre">Phase.generate</span></code> controls whether new examples will be generated.</li>
<li><code class="docutils literal"><span class="pre">Phase.shrink</span></code> controls whether examples will be shrunk.</li>
</ol>
<p>The phases argument accepts a collection with any subset of these. e.g.
<code class="docutils literal"><span class="pre">settings(phases=[Phase.generate,</span> <span class="pre">Phase.shrink])</span></code> will generate new examples
and shrink them, but will not run explicit examples or reuse previous failures,
while <code class="docutils literal"><span class="pre">settings(phases=[Phase.explicit])</span></code> will only run the explicit
examples.</p>
</div>
<div class="section" id="seeing-intermediate-result">
<span id="verbose-output"></span><h3>Seeing intermediate result<a class="headerlink" href="#seeing-intermediate-result" title="Permalink to this headline">¶</a></h3>
<p>To see what’s going on while Hypothesis runs your tests, you can turn
up the verbosity setting. This works with both <code class="xref py py-func docutils literal"><span class="pre">find()</span></code>
and <a class="reference internal" href="details.html#hypothesis.given" title="hypothesis.given"><code class="xref py py-func docutils literal"><span class="pre">@given</span></code></a>.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">hypothesis</span> <span class="k">import</span> <span class="n">find</span><span class="p">,</span> <span class="n">settings</span><span class="p">,</span> <span class="n">Verbosity</span>
<span class="gp">>>> </span><span class="kn">from</span> <span class="nn">hypothesis.strategies</span> <span class="k">import</span> <span class="n">lists</span><span class="p">,</span> <span class="n">booleans</span>
<span class="gp">>>> </span><span class="n">find</span><span class="p">(</span><span class="n">lists</span><span class="p">(</span><span class="n">integers</span><span class="p">()),</span> <span class="nb">any</span><span class="p">,</span> <span class="n">settings</span><span class="o">=</span><span class="n">settings</span><span class="p">(</span><span class="n">verbosity</span><span class="o">=</span><span class="n">Verbosity</span><span class="o">.</span><span class="n">verbose</span><span class="p">))</span>
<span class="go">Trying example []</span>
<span class="go">Found satisfying example [-106641080167757791735701986170810016341,</span>
<span class="go"> -129665482689688858331316879188241401294,</span>
<span class="go"> -17902751879921353864928802351902980929,</span>
<span class="go"> 86547910278013668694989468221154862503,</span>
<span class="go"> 99789676068743906931733548810810835946,</span>
<span class="go"> -56833685188912180644827795048092269385,</span>
<span class="go"> -12891126493032945632804716628985598019,</span>
<span class="go"> 57797823215504994933565345605235342532,</span>
<span class="go"> 98214819714866425575119206029702237685]</span>
<span class="go">Shrunk example to [-106641080167757791735701986170810016341,</span>
<span class="go"> -129665482689688858331316879188241401294,</span>
<span class="go"> -17902751879921353864928802351902980929,</span>
<span class="go"> 86547910278013668694989468221154862503,</span>
<span class="go"> 99789676068743906931733548810810835946,</span>
<span class="go"> -56833685188912180644827795048092269385,</span>
<span class="go"> -12891126493032945632804716628985598019,</span>
<span class="go"> 57797823215504994933565345605235342532,</span>
<span class="go"> 98214819714866425575119206029702237685]</span>
<span class="go">Shrunk example to [-106641080167757791735701986170810016341,</span>
<span class="go"> -129665482689688858331316879188241401294,</span>
<span class="go"> -17902751879921353864928802351902980929,</span>
<span class="go"> 86547910278013668694989468221154862503]</span>
<span class="go">Shrunk example to [-106641080167757791735701986170810016341,</span>
<span class="go"> 164695784672172929935660921670478470673]</span>
<span class="go">Shrunk example to [164695784672172929935660921670478470673]</span>
<span class="go">Shrunk example to [164695784672172929935660921670478470673]</span>
<span class="go">Shrunk example to [164695784672172929935660921670478470673]</span>
<span class="go">Shrunk example to [1]</span>
<span class="go">[1]</span>
</pre></div>
</div>
<p>The four levels are quiet, normal, verbose and debug. normal is the default,
while in quiet Hypothesis will not print anything out, even the final
falsifying example. debug is basically verbose but a bit more so. You probably
don’t want it.</p>
<p>You can also override the default by setting the environment variable
<span class="target" id="index-0"></span><code class="xref std std-envvar docutils literal"><span class="pre">HYPOTHESIS_VERBOSITY_LEVEL</span></code> to the name of the level you want. So e.g.
setting <code class="docutils literal"><span class="pre">HYPOTHESIS_VERBOSITY_LEVEL=verbose</span></code> will run all your tests printing
intermediate results and errors.</p>
<p>If you are using <code class="docutils literal"><span class="pre">pytest</span></code>, you may also need to
<span class="xref std std-doc">disable output capturing for passing tests</span>.</p>
</div>
</div>
<div class="section" id="building-settings-objects">
<h2>Building settings objects<a class="headerlink" href="#building-settings-objects" title="Permalink to this headline">¶</a></h2>
<p>Settings can be created by calling <a class="reference internal" href="#hypothesis.settings" title="hypothesis.settings"><code class="xref py py-class docutils literal"><span class="pre">settings</span></code></a> with any of the available settings
values. Any absent ones will be set to defaults:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">hypothesis</span> <span class="k">import</span> <span class="n">settings</span>
<span class="gp">>>> </span><span class="n">settings</span><span class="p">()</span><span class="o">.</span><span class="n">max_examples</span>
<span class="go">100</span>
<span class="gp">>>> </span><span class="n">settings</span><span class="p">(</span><span class="n">max_examples</span><span class="o">=</span><span class="mi">10</span><span class="p">)</span><span class="o">.</span><span class="n">max_examples</span>
<span class="go">10</span>
</pre></div>
</div>
<p>You can also copy settings from other settings:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">s</span> <span class="o">=</span> <span class="n">settings</span><span class="p">(</span><span class="n">max_examples</span><span class="o">=</span><span class="mi">10</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">t</span> <span class="o">=</span> <span class="n">settings</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">max_iterations</span><span class="o">=</span><span class="mi">20</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">s</span><span class="o">.</span><span class="n">max_examples</span>
<span class="go">10</span>
<span class="gp">>>> </span><span class="n">t</span><span class="o">.</span><span class="n">max_iterations</span>
<span class="go">20</span>
<span class="gp">>>> </span><span class="n">s</span><span class="o">.</span><span class="n">max_iterations</span>
<span class="go">1000</span>
<span class="gp">>>> </span><span class="n">s</span><span class="o">.</span><span class="n">max_shrinks</span>
<span class="go">500</span>
<span class="gp">>>> </span><span class="n">t</span><span class="o">.</span><span class="n">max_shrinks</span>
<span class="go">500</span>
</pre></div>
</div>
</div>
<div class="section" id="default-settings">
<h2>Default settings<a class="headerlink" href="#default-settings" title="Permalink to this headline">¶</a></h2>
<p>At any given point in your program there is a current default settings,
available as <code class="docutils literal"><span class="pre">settings.default</span></code>. As well as being a settings object in its own
right, all newly created settings objects which are not explicitly based off
another settings are based off the default, so will inherit any values that are
not explicitly set from it.</p>
<p>You can change the defaults by using profiles (see next section), but you can
also override them locally by using a settings object as a <span class="xref std std-ref">context manager</span></p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">with</span> <span class="n">settings</span><span class="p">(</span><span class="n">max_examples</span><span class="o">=</span><span class="mi">150</span><span class="p">):</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">settings</span><span class="o">.</span><span class="n">default</span><span class="o">.</span><span class="n">max_examples</span><span class="p">)</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">settings</span><span class="p">()</span><span class="o">.</span><span class="n">max_examples</span><span class="p">)</span>
<span class="go">150</span>
<span class="go">150</span>
<span class="gp">>>> </span><span class="n">settings</span><span class="p">()</span><span class="o">.</span><span class="n">max_examples</span>
<span class="go">100</span>
</pre></div>
</div>
<p>Note that after the block exits the default is returned to normal.</p>
<p>You can use this by nesting test definitions inside the context:</p>
<div class="code python highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">hypothesis</span> <span class="k">import</span> <span class="n">given</span><span class="p">,</span> <span class="n">settings</span>
<span class="k">with</span> <span class="n">settings</span><span class="p">(</span><span class="n">max_examples</span><span class="o">=</span><span class="mi">500</span><span class="p">):</span>
<span class="nd">@given</span><span class="p">(</span><span class="n">integers</span><span class="p">())</span>
<span class="k">def</span> <span class="nf">test_this_thoroughly</span><span class="p">(</span><span class="n">x</span><span class="p">):</span>
<span class="k">pass</span>
</pre></div>
</div>
<p>All settings objects created or tests defined inside the block will inherit their
defaults from the settings object used as the context. You can still override them
with custom defined settings of course.</p>
<p>Warning: If you use define test functions which don’t use <a class="reference internal" href="details.html#hypothesis.given" title="hypothesis.given"><code class="xref py py-func docutils literal"><span class="pre">@given</span></code></a>
inside a context block, these will not use the enclosing settings. This is because the context
manager only affects the definition, not the execution of the function.</p>
<div class="section" id="settings-profiles">
<span id="id1"></span><h3>settings Profiles<a class="headerlink" href="#settings-profiles" title="Permalink to this headline">¶</a></h3>
<p>Depending on your environment you may want different default settings.
For example: during development you may want to lower the number of examples
to speed up the tests. However, in a CI environment you may want more examples
so you are more likely to find bugs.</p>
<p>Hypothesis allows you to define different settings profiles. These profiles
can be loaded at any time.</p>
<p>Loading a profile changes the default settings but will not change the behavior
of tests that explicitly change the settings.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">hypothesis</span> <span class="k">import</span> <span class="n">settings</span>
<span class="gp">>>> </span><span class="n">settings</span><span class="o">.</span><span class="n">register_profile</span><span class="p">(</span><span class="s2">"ci"</span><span class="p">,</span> <span class="n">settings</span><span class="p">(</span><span class="n">max_examples</span><span class="o">=</span><span class="mi">1000</span><span class="p">))</span>
<span class="gp">>>> </span><span class="n">settings</span><span class="p">()</span><span class="o">.</span><span class="n">max_examples</span>
<span class="go">100</span>
<span class="gp">>>> </span><span class="n">settings</span><span class="o">.</span><span class="n">load_profile</span><span class="p">(</span><span class="s2">"ci"</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">settings</span><span class="p">()</span><span class="o">.</span><span class="n">max_examples</span>
<span class="go">1000</span>
</pre></div>
</div>
<p>Instead of loading the profile and overriding the defaults you can retrieve profiles for
specific tests.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">with</span> <span class="n">settings</span><span class="o">.</span><span class="n">get_profile</span><span class="p">(</span><span class="s2">"ci"</span><span class="p">):</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">settings</span><span class="p">()</span><span class="o">.</span><span class="n">max_examples</span><span class="p">)</span>
<span class="gp">...</span>
<span class="go">1000</span>
</pre></div>
</div>
<p>Optionally, you may define the environment variable to load a profile for you.
This is the suggested pattern for running your tests on CI.
The code below should run in a <cite>conftest.py</cite> or any setup/initialization section of your test suite.
If this variable is not defined the Hypothesis defined defaults will be loaded.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">os</span>
<span class="gp">>>> </span><span class="kn">from</span> <span class="nn">hypothesis</span> <span class="k">import</span> <span class="n">settings</span><span class="p">,</span> <span class="n">Verbosity</span>
<span class="gp">>>> </span><span class="n">settings</span><span class="o">.</span><span class="n">register_profile</span><span class="p">(</span><span class="s2">"ci"</span><span class="p">,</span> <span class="n">settings</span><span class="p">(</span><span class="n">max_examples</span><span class="o">=</span><span class="mi">1000</span><span class="p">))</span>
<span class="gp">>>> </span><span class="n">settings</span><span class="o">.</span><span class="n">register_profile</span><span class="p">(</span><span class="s2">"dev"</span><span class="p">,</span> <span class="n">settings</span><span class="p">(</span><span class="n">max_examples</span><span class="o">=</span><span class="mi">10</span><span class="p">))</span>
<span class="gp">>>> </span><span class="n">settings</span><span class="o">.</span><span class="n">register_profile</span><span class="p">(</span><span class="s2">"debug"</span><span class="p">,</span> <span class="n">settings</span><span class="p">(</span><span class="n">max_examples</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span> <span class="n">verbosity</span><span class="o">=</span><span class="n">Verbosity</span><span class="o">.</span><span class="n">verbose</span><span class="p">))</span>
<span class="gp">>>> </span><span class="n">settings</span><span class="o">.</span><span class="n">load_profile</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">getenv</span><span class="p">(</span><span class="sa">u</span><span class="s1">'HYPOTHESIS_PROFILE'</span><span class="p">,</span> <span class="s1">'default'</span><span class="p">))</span>
</pre></div>
</div>
<p>If you are using the hypothesis pytest plugin and your profiles are registered
by your conftest you can load one with the command line option <code class="docutils literal"><span class="pre">--hypothesis-profile</span></code>.</p>
<div class="code bash highlight-default"><div class="highlight"><pre><span></span>$ py.test tests --hypothesis-profile <profile-name>
</pre></div>
</div>
</div>
<div class="section" id="timeouts">
<h3>Timeouts<a class="headerlink" href="#timeouts" title="Permalink to this headline">¶</a></h3>
<p>The <cite>timeout</cite> functionality of Hypothesis is being deprecated, and will
eventually be removed. For the moment, the timeout setting can still be set
and the old default timeout of one minute remains.</p>
<p>If you want to future proof your code you can get
the future behaviour by setting it to the value <cite>unlimited</cite>, which you can
import from the main Hypothesis package:</p>
<div class="code python highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">hypothesis</span> <span class="k">import</span> <span class="n">given</span><span class="p">,</span> <span class="n">settings</span><span class="p">,</span> <span class="n">unlimited</span>
<span class="kn">from</span> <span class="nn">hypothesis</span> <span class="k">import</span> <span class="n">strategies</span> <span class="k">as</span> <span class="n">st</span>
<span class="nd">@settings</span><span class="p">(</span><span class="n">timeout</span><span class="o">=</span><span class="n">unlimited</span><span class="p">)</span>
<span class="nd">@given</span><span class="p">(</span><span class="n">st</span><span class="o">.</span><span class="n">integers</span><span class="p">())</span>
<span class="k">def</span> <span class="nf">test_something_slow</span><span class="p">(</span><span class="n">i</span><span class="p">):</span>
<span class="o">...</span>
</pre></div>
</div>
<p>This will cause your code to run until it hits the normal Hypothesis example
limits, regardless of how long it takes. <cite>timeout=unlimited</cite> will remain a
valid setting after the timeout functionality has been deprecated (but will
then have its own deprecation cycle).</p>
<p>There is however now a timing related health check which is designed to catch
tests that run for ages by accident. If you really want your test to run
forever, the following code will enable that:</p>
<div class="code python highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">hypothesis</span> <span class="k">import</span> <span class="n">given</span><span class="p">,</span> <span class="n">settings</span><span class="p">,</span> <span class="n">unlimited</span><span class="p">,</span> <span class="n">HealthCheck</span>
<span class="kn">from</span> <span class="nn">hypothesis</span> <span class="k">import</span> <span class="n">strategies</span> <span class="k">as</span> <span class="n">st</span>
<span class="nd">@settings</span><span class="p">(</span><span class="n">timeout</span><span class="o">=</span><span class="n">unlimited</span><span class="p">,</span> <span class="n">suppress_health_check</span><span class="o">=</span><span class="p">[</span>
<span class="n">HealthCheck</span><span class="o">.</span><span class="n">hung_test</span>
<span class="p">])</span>
<span class="nd">@given</span><span class="p">(</span><span class="n">st</span><span class="o">.</span><span class="n">integers</span><span class="p">())</span>
<span class="k">def</span> <span class="nf">test_something_slow</span><span class="p">(</span><span class="n">i</span><span class="p">):</span>
<span class="o">...</span>
</pre></div>
</div>
</div>
</div>
</div>
</div>
<div class="articleComments">
</div>
</div>
<footer>
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
<a href="data.html" class="btn btn-neutral float-right" title="What you can generate and how" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
<a href="details.html" class="btn btn-neutral" title="Details and advanced features" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
</div>
<hr/>
<div role="contentinfo">
<p>
© Copyright 2013-2018, David R. MacIver.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT:'./',
VERSION:'3.44.1',
COLLAPSE_INDEX:false,
FILE_SUFFIX:'.html',
HAS_SOURCE: true,
SOURCELINK_SUFFIX: '.txt'
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<script type="text/javascript" src="_static/js/theme.js"></script>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.StickyNav.enable();
});
</script>
</body>
</html>
|