Skip to content

Commit 4f430bb

Browse files
committed
update docs
1 parent 46ea627 commit 4f430bb

File tree

5 files changed

+92
-4
lines changed

5 files changed

+92
-4
lines changed

context_async_sqlalchemy/test_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ async def put_savepoint_session_in_ctx(
5353
a transaction. You need to pass the session you're using inside
5454
your tests to attach a new session to the same connection.
5555
56-
It is also important to use this function inside set_test_context.
56+
It is important to use this function inside set_test_context.
5757
"""
5858
session_maker = await connection.session_maker()
5959
async with session_maker(

docs/api/index.html

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,16 @@
108108
</li>
109109
</ul>
110110
</li>
111+
<li class="toctree-l2"><a class="reference internal" href="#testing">Testing</a>
112+
<ul>
113+
<li class="toctree-l3"><a class="reference internal" href="#rollback_session">rollback_session</a>
114+
</li>
115+
<li class="toctree-l3"><a class="reference internal" href="#set_test_context">set_test_context</a>
116+
</li>
117+
<li class="toctree-l3"><a class="reference internal" href="#put_savepoint_session_in_ctx">put_savepoint_session_in_ctx</a>
118+
</li>
119+
</ul>
120+
</li>
111121
</ul>
112122
</li>
113123
</ul>
@@ -197,7 +207,10 @@ <h3 id="init">init</h3>
197207
<h3 id="connect">connect</h3>
198208
<pre><code class="language-python">async def connect(self: DBConnect, host: str) -&gt; None:
199209
</code></pre>
200-
<p>Establishes a connection to the specified host. This method doesn’t need to be called explicitly. If it isn’t called, the first session request will automatically establish the connection.</p>
210+
<p>Establishes a connection to the specified host.
211+
This method doesn’t need to be called explicitly.
212+
If it isn’t called, the first session request will automatically
213+
establish the connection.</p>
201214
<hr />
202215
<h3 id="change_host">change_host</h3>
203216
<pre><code class="language-python">async def change_host(self: DBConnect, host: str) -&gt; None:
@@ -349,6 +362,38 @@ <h3 id="run_in_new_ctx">run_in_new_ctx</h3>
349362
),
350363
run_in_new_ctx(your_function_with_db_session, ...),
351364
)
365+
</code></pre>
366+
<h2 id="testing">Testing</h2>
367+
<p>You can read more about testing here: <a href="../testing">Testing</a></p>
368+
<h3 id="rollback_session">rollback_session</h3>
369+
<pre><code class="language-python">@asynccontextmanager
370+
async def rollback_session(
371+
connection: DBConnect,
372+
) -&gt; AsyncGenerator[AsyncSession]:
373+
</code></pre>
374+
<p>A context manager that creates a session which is automatically rolled
375+
back at the end.
376+
It’s intended for use in fixtures to execute SQL queries during tests.</p>
377+
<hr />
378+
<h3 id="set_test_context">set_test_context</h3>
379+
<pre><code class="language-python">@asynccontextmanager
380+
async def set_test_context() -&gt; AsyncGenerator[None]:
381+
</code></pre>
382+
<p>A context manager that creates a new context in which you can place a
383+
dedicated test session.
384+
It’s intended for use in tests where the test and the application share
385+
a single transaction.</p>
386+
<hr />
387+
<h3 id="put_savepoint_session_in_ctx">put_savepoint_session_in_ctx</h3>
388+
<pre><code class="language-python">async def put_savepoint_session_in_ctx(
389+
connection: DBConnect,
390+
session: AsyncSession,
391+
) -&gt; AsyncGenerator[None]:
392+
</code></pre>
393+
<p>Sets the context to a session that uses a save point instead of creating
394+
a transaction. You need to pass the session you're using inside
395+
your tests to attach a new session to the same connection.</p>
396+
<pre><code>It is important to use this function inside set_test_context.
352397
</code></pre>
353398

354399
</div>

docs/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,5 +218,5 @@ <h2 id="how-it-works">How it works</h2>
218218

219219
<!--
220220
MkDocs version : 1.6.1
221-
Build Date UTC : 2025-11-25 20:53:03.512231+00:00
221+
Build Date UTC : 2025-11-25 21:27:44.719156+00:00
222222
-->

docs/search/search_index.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs_sources/docs/api.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,3 +284,46 @@ await asyncio.gather(
284284
run_in_new_ctx(your_function_with_db_session, ...),
285285
)
286286
```
287+
288+
289+
## Testing
290+
291+
You can read more about testing here: [Testing](testing.md)
292+
293+
### rollback_session
294+
```python
295+
@asynccontextmanager
296+
async def rollback_session(
297+
connection: DBConnect,
298+
) -> AsyncGenerator[AsyncSession]:
299+
```
300+
A context manager that creates a session which is automatically rolled
301+
back at the end.
302+
It’s intended for use in fixtures to execute SQL queries during tests.
303+
304+
---
305+
306+
### set_test_context
307+
```python
308+
@asynccontextmanager
309+
async def set_test_context() -> AsyncGenerator[None]:
310+
```
311+
A context manager that creates a new context in which you can place a
312+
dedicated test session.
313+
It’s intended for use in tests where the test and the application share
314+
a single transaction.
315+
316+
---
317+
318+
### put_savepoint_session_in_ctx
319+
```python
320+
async def put_savepoint_session_in_ctx(
321+
connection: DBConnect,
322+
session: AsyncSession,
323+
) -> AsyncGenerator[None]:
324+
```
325+
Sets the context to a session that uses a save point instead of creating
326+
a transaction. You need to pass the session you're using inside
327+
your tests to attach a new session to the same connection.
328+
329+
It is important to use this function inside set_test_context.

0 commit comments

Comments
 (0)