22Nuances
33=======
44
5- Preliminary execution
6- =====================
5+ Premature finalization
6+ ======================
77
88Consider this test:
99
@@ -21,7 +21,7 @@ Consider this test:
2121 await asyncio.sleep(1 )
2222
2323 Normally, it should not fail. However, with fake time (without workarounds),
24- the following scenario is possible:
24+ the following step-by-step scenario is possible:
2525
2626* ``async_timeout `` library sets its delayed timer at 9 seconds from now.
2727* The event loop notices that there is only one timer at T0+9s.
@@ -36,13 +36,13 @@ tasks, and handles a fair chance to be entered, spawned, and scheduled.
3636This is why the example works as intended.
3737
3838The ``noop_cycles `` (``int ``) setting is how many cycles the event loop makes.
39- The default is ``42 ``. Why 42? Well, …
39+ The default is ``42 ``. Why 42? Well, why not, indeed.
4040
4141
42- Slow executors
43- ==============
42+ Sync-async synchronization
43+ ==========================
4444
45- Consider this test:
45+ Consider this test, which mixes sync & async activities & primitives :
4646
4747.. code-block :: python
4848
@@ -112,10 +112,10 @@ of steps with no fractions: e.g., 0.01 or 0.02 seconds in this example.
112112A trade-off: a smaller step will get results faster but will spend more CPU power on resultless cycles.
113113
114114
115- I/O idle
116- ========
115+ Idle I/O activities
116+ ===================
117117
118- Consider this test:
118+ Consider this test, which does the external I/O communication :
119119
120120.. code-block :: python
121121
@@ -145,7 +145,8 @@ The default is ``1.0`` second.
145145
146146If nothing happens within this time, the event loop assumes that nothing
147147will ever happen, so it is a good idea to cease its existence: it injects
148- ``IdleTimeoutError `` (a subclass of ``asyncio.TimeoutError ``) into all tasks.
148+ :class: `looptime.IdleTimeoutError ` (a subclass of :class: `asyncio.TimeoutError `)
149+ into all currently running tasks.
149150
150151This is similar to how the end-of-time behaves, except that it is measured
151152in the true-time timeline, while the end-of-time is in the fake-time timeline.
@@ -214,8 +215,8 @@ If the async timeout is reached, further code can proceed normally.
214215 assert chronometer < 0.1
215216
216217
217- Time resolution
218- ===============
218+ Time resolution & floating point precision errors
219+ =================================================
219220
220221Python (as well as many other languages) has issues with calculating floats:
221222
@@ -255,8 +256,8 @@ Normally, you should not worry about it or configure it.
255256 everything smaller than 0.001 becomes 0 and probably misbehaves.
256257
257258
258- Time magic coverage
259- ===================
259+ Exclusion of fixture setup/teardown
260+ ===================================
260261
261262The time compaction magic is enabled only for the duration of the test,
262263i.e., the test function — but not the fixtures.
@@ -284,13 +285,33 @@ plus an assumption that it was never used by anyone (it should not be).
284285It was rather a side effect of the previous implementation,
285286which is not available or possible anymore.
286287
288+ If the time magic is needed in fixtures, use the more explicit approach:
289+
290+ .. code-block :: python
291+
292+ import looptime
293+ import pytest_async
294+
295+ @pytest_async.fixture
296+ def async_fixture_example ():
297+ with looptime.enabled():
298+ # Execute some async time-based code, but compacted.
299+ await asyncio.sleep(1 )
300+
301+ # Go to the test(s).
302+ yield
303+
304+ with looptime.enabled():
305+ # Execute some async time-based code, but compacted.
306+ await asyncio.sleep(1 )
307+
287308
288309 pytest-asyncio>=1.0.0
289310=====================
290311
291- As mentioned above, pytest-asyncio>=1.0.0 introduced several co-existing
292- event loops of different scopes. Time compaction in these event loops
293- is NOT activated. Only the running loop of the test function is activated.
312+ pytest-asyncio>=1.0.0 introduced several co-existing event loops
313+ of different scopes. Time compaction in these event loops is NOT activated.
314+ Only the running loop of the test function is activated.
294315
295316Configuring and activating multiple co-existing event loops brings a few
296317conceptual challenges, which require a good sample case to look into
0 commit comments