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>
+42 -5
View File
@@ -2400,7 +2400,7 @@ Each call creates a fresh engine and session for test isolation.</p>
<h2 id="fastapi_toolsets.pytest.utils.worker_database_url" class="doc doc-heading">
<code class="highlight language-python"><span class="n">fastapi_toolsets</span><span class="o">.</span><span class="n">pytest</span><span class="o">.</span><span class="n">utils</span><span class="o">.</span><span class="n">worker_database_url</span><span class="p">(</span><span class="n">database_url</span><span class="p">,</span> <span class="n">default_test_db</span><span class="p">)</span></code>
<code class="highlight language-python"><span class="n">fastapi_toolsets</span><span class="o">.</span><span class="n">pytest</span><span class="o">.</span><span class="n">utils</span><span class="o">.</span><span class="n">worker_database_url</span><span class="p">(</span><span class="n">database_url</span><span class="p">,</span> <span class="n">default_test_db</span><span class="p">,</span> <span class="o">*</span><span class="p">,</span> <span class="n">prefix</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span></code>
<a href="#fastapi_toolsets.pytest.utils.worker_database_url" class="headerlink" title="Permanent link">&para;</a></h2>
@@ -2408,9 +2408,10 @@ Each call creates a fresh engine and session for test isolation.</p>
<div class="doc doc-contents first">
<p>Derive a per-worker database URL for pytest-xdist parallel runs.</p>
<p>Appends <code>_{worker_name}</code> to the database name so each xdist worker
operates on its own database. When not running under xdist,
<code>_{default_test_db}</code> is appended instead.</p>
<p>Sets the database name to the worker name so each xdist worker operates
on its own database. When not running under xdist, <em>default_test_db</em> is
used instead. When <em>prefix</em> is provided, the name becomes
<code>{prefix}_{worker}</code>.</p>
<p>The worker name is read from the <code>PYTEST_XDIST_WORKER</code> environment
variable (set automatically by xdist in each worker process).</p>
@@ -2459,6 +2460,24 @@ variable (set automatically by xdist in each worker process).</p>
<em>required</em>
</td>
</tr>
<tr class="doc-section-item">
<td>
<code>prefix</code>
</td>
<td>
<code><a class="autorefs autorefs-external" href="https://docs.python.org/3/library/stdtypes.html#str">str</a> | None</code>
</td>
<td>
<div class="doc-md-description">
<p>Optional prefix prepended to the worker name
(e.g. <code>"test"</code><code>"test_gw0"</code>). Without it, the database
name is just the worker name (e.g. <code>"gw0"</code>).</p>
</div>
</td>
<td>
<code>None</code>
</td>
</tr>
</tbody>
</table>
@@ -2494,7 +2513,7 @@ variable (set automatically by xdist in each worker process).</p>
<h2 id="fastapi_toolsets.pytest.utils.create_worker_database" class="doc doc-heading">
<code class="highlight language-python"><span class="n">fastapi_toolsets</span><span class="o">.</span><span class="n">pytest</span><span class="o">.</span><span class="n">utils</span><span class="o">.</span><span class="n">create_worker_database</span><span class="p">(</span><span class="n">database_url</span><span class="p">,</span> <span class="n">default_test_db</span><span class="o">=</span><span class="s1">&#39;test_db&#39;</span><span class="p">,</span> <span class="o">*</span><span class="p">,</span> <span class="n">server_url</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span></code>
<code class="highlight language-python"><span class="n">fastapi_toolsets</span><span class="o">.</span><span class="n">pytest</span><span class="o">.</span><span class="n">utils</span><span class="o">.</span><span class="n">create_worker_database</span><span class="p">(</span><span class="n">database_url</span><span class="p">,</span> <span class="n">default_test_db</span><span class="o">=</span><span class="s1">&#39;test_db&#39;</span><span class="p">,</span> <span class="o">*</span><span class="p">,</span> <span class="n">prefix</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">server_url</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span></code>
<span class="doc doc-labels">
<small class="doc doc-label doc-label-async"><code>async</code></small>
@@ -2558,6 +2577,24 @@ the worker database name).</p>
<code>&#39;test_db&#39;</code>
</td>
</tr>
<tr class="doc-section-item">
<td>
<code>prefix</code>
</td>
<td>
<code><a class="autorefs autorefs-external" href="https://docs.python.org/3/library/stdtypes.html#str">str</a> | None</code>
</td>
<td>
<div class="doc-md-description">
<p>Optional prefix prepended to the worker name
(e.g. <code>prefix="test"</code><code>"test_gw0"</code>). Without it, the
database name is just the worker name (e.g. <code>"gw0"</code>).</p>
</div>
</td>
<td>
<code>None</code>
</td>
</tr>
<tr class="doc-section-item">
<td>
<code>server_url</code>
+1 -1
View File
File diff suppressed because one or more lines are too long