Deployed 2641881 to v4.1 with Zensical 0.0.43 and mike 2.2.0+zensical-0.1.0

This commit is contained in:
github-actions[bot]
2026-06-09 16:51:07 +00:00
parent e449df76c2
commit 95c5fb7828
3 changed files with 50 additions and 9 deletions
+7 -3
View File
@@ -1953,13 +1953,17 @@
</span><span id="__span-5-7"><a id="__codelineno-5-7" name="__codelineno-5-7" href="#__codelineno-5-7"></a> <span class="o">...</span>
</span></code></pre></div>
<h2 id="parallel-testing-with-pytest-xdist">Parallel testing with pytest-xdist<a class="headerlink" href="#parallel-testing-with-pytest-xdist" title="Permanent link">&para;</a></h2>
<p>The fixtures above work with <code>pytest-xdist</code> out of the box. Each worker gets its own database suffixed with the worker name (e.g. <code>myapp_gw0</code>, <code>myapp_gw1</code>).</p>
<p>The fixtures above work with <code>pytest-xdist</code> out of the box. Each worker gets its own database named after the worker (e.g. <code>gw0</code>, <code>gw1</code>). Pass <code>prefix</code> to namespace the database (e.g. <code>prefix="myapp"</code> <code>myapp_gw0</code>).</p>
<p>Use <a href="../../reference/pytest/#fastapi_toolsets.pytest.utils.worker_database_url"><code>worker_database_url</code></a> to derive the per-worker URL manually if needed:</p>
<div class="language-python highlight"><pre><span></span><code><span id="__span-6-1"><a id="__codelineno-6-1" name="__codelineno-6-1" href="#__codelineno-6-1"></a><span class="kn">from</span><span class="w"> </span><span class="nn">fastapi_toolsets.pytest</span><span class="w"> </span><span class="kn">import</span> <span class="n">worker_database_url</span>
</span><span id="__span-6-2"><a id="__codelineno-6-2" name="__codelineno-6-2" href="#__codelineno-6-2"></a>
</span><span id="__span-6-3"><a id="__codelineno-6-3" name="__codelineno-6-3" href="#__codelineno-6-3"></a><span class="n">url</span> <span class="o">=</span> <span class="n">worker_database_url</span><span class="p">(</span><span class="s2">&quot;postgresql+asyncpg://user:pass@localhost/myapp&quot;</span><span class="p">,</span> <span class="n">default_test_db</span><span class="o">=</span><span class="s2">&quot;test&quot;</span><span class="p">)</span>
</span><span id="__span-6-4"><a id="__codelineno-6-4" name="__codelineno-6-4" href="#__codelineno-6-4"></a><span class="c1"># → &quot;postgresql+asyncpg://user:pass@localhost/myapp_gw0&quot; under xdist</span>
</span><span id="__span-6-5"><a id="__codelineno-6-5" name="__codelineno-6-5" href="#__codelineno-6-5"></a><span class="c1"># → &quot;postgresql+asyncpg://user:pass@localhost/myapp_test&quot; otherwise</span>
</span><span id="__span-6-4"><a id="__codelineno-6-4" name="__codelineno-6-4" href="#__codelineno-6-4"></a><span class="c1"># → &quot;postgresql+asyncpg://user:pass@localhost/gw0&quot; under xdist</span>
</span><span id="__span-6-5"><a id="__codelineno-6-5" name="__codelineno-6-5" href="#__codelineno-6-5"></a><span class="c1"># → &quot;postgresql+asyncpg://user:pass@localhost/test&quot; otherwise</span>
</span><span id="__span-6-6"><a id="__codelineno-6-6" name="__codelineno-6-6" href="#__codelineno-6-6"></a>
</span><span id="__span-6-7"><a id="__codelineno-6-7" name="__codelineno-6-7" href="#__codelineno-6-7"></a><span class="n">url</span> <span class="o">=</span> <span class="n">worker_database_url</span><span class="p">(</span><span class="s2">&quot;postgresql+asyncpg://user:pass@localhost/myapp&quot;</span><span class="p">,</span> <span class="n">default_test_db</span><span class="o">=</span><span class="s2">&quot;test&quot;</span><span class="p">,</span> <span class="n">prefix</span><span class="o">=</span><span class="s2">&quot;myapp&quot;</span><span class="p">)</span>
</span><span id="__span-6-8"><a id="__codelineno-6-8" name="__codelineno-6-8" href="#__codelineno-6-8"></a><span class="c1"># → &quot;postgresql+asyncpg://user:pass@localhost/myapp_gw0&quot; under xdist</span>
</span><span id="__span-6-9"><a id="__codelineno-6-9" name="__codelineno-6-9" href="#__codelineno-6-9"></a><span class="c1"># → &quot;postgresql+asyncpg://user:pass@localhost/myapp_test&quot; otherwise</span>
</span></code></pre></div>
<h2 id="manual-table-cleanup">Manual table cleanup<a class="headerlink" href="#manual-table-cleanup" title="Permanent link">&para;</a></h2>
<p><a href="../../reference/db/#fastapi_toolsets.db.cleanup_tables"><code>cleanup_tables</code></a> truncates all tables in a single statement and can be called directly when you need more control:</p>