Debian Codegraph @

docs/reference/fixtures/index.rst

raw
1 ========
2 Fixtures
3 ========
4
5 event_loop_policy
6 =================
7
8 .. warning::
9
10 Overriding the *event_loop_policy* fixture is deprecated and will be removed in a future version of pytest-asyncio. Use the ``pytest_asyncio_loop_factories`` hook instead. See :doc:`../hooks` for details.
11
12 Returns the event loop policy used to create asyncio event loops.
13 The default return value is *asyncio.get_event_loop_policy().*
14
15 This fixture can be overridden when a different event loop policy should be used.
16
17 .. include:: event_loop_policy_example.py
18 :code: python
19
20 Multiple policies can be provided via fixture parameters.
21 The fixture is automatically applied to all pytest-asyncio tests.
22 Therefore, all tests managed by pytest-asyncio are run once for each fixture parameter.
23 The following example runs the test with different event loop policies.
24
25 .. include:: event_loop_policy_parametrized_example.py
26 :code: python
27
28 unused_tcp_port
29 ===============
30 Finds and yields a single unused TCP port on the localhost interface. Useful for
31 binding temporary test servers.
32
33 unused_tcp_port_factory
34 =======================
35 A callable which returns a different unused TCP port each invocation. Useful
36 when several unused TCP ports are required in a test.
37
38 .. code-block:: python
39
40 def a_test(unused_tcp_port_factory):
41 _port1, _port2 = unused_tcp_port_factory(), unused_tcp_port_factory()
42
43 unused_udp_port and unused_udp_port_factory
44 ===========================================
45 Works just like their TCP counterparts but returns unused UDP ports.