-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[docs] Extracted most Python code examples into separate files.
This allows for auto-formatting using the usual tools and enables running the code examples as tests to ensure they work. Tests that perform network operations or require additional test dependencies have been excluded. Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de>
- Loading branch information
Showing
14 changed files
with
202 additions
and
203 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
docs/source/reference/decorators/fixture_strict_mode_example.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import asyncio | ||
|
||
import pytest_asyncio | ||
|
||
|
||
@pytest_asyncio.fixture | ||
async def async_gen_fixture(): | ||
await asyncio.sleep(0.1) | ||
yield "a value" | ||
|
||
|
||
@pytest_asyncio.fixture(scope="module") | ||
async def async_fixture(): | ||
return await asyncio.sleep(0.1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import asyncio | ||
|
||
|
||
def test_event_loop_fixture(event_loop): | ||
event_loop.run_until_complete(asyncio.sleep(0)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
docs/source/reference/markers/class_scoped_loop_auto_mode_example.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import asyncio | ||
|
||
import pytest | ||
|
||
|
||
@pytest.mark.asyncio_event_loop | ||
class TestClassScopedLoop: | ||
loop: asyncio.AbstractEventLoop | ||
|
||
async def test_remember_loop(self): | ||
TestClassScopedLoop.loop = asyncio.get_running_loop() | ||
|
||
async def test_this_runs_in_same_loop(self): | ||
assert asyncio.get_running_loop() is TestClassScopedLoop.loop |
15 changes: 15 additions & 0 deletions
15
docs/source/reference/markers/class_scoped_loop_custom_policies_strict_mode_example.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import asyncio | ||
|
||
import pytest | ||
|
||
|
||
@pytest.mark.asyncio_event_loop( | ||
policy=[ | ||
asyncio.DefaultEventLoopPolicy(), | ||
asyncio.DefaultEventLoopPolicy(), | ||
] | ||
) | ||
class TestWithDifferentLoopPolicies: | ||
@pytest.mark.asyncio | ||
async def test_parametrized_loop(self): | ||
pass |
14 changes: 14 additions & 0 deletions
14
docs/source/reference/markers/class_scoped_loop_custom_policy_strict_mode_example.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import asyncio | ||
|
||
import pytest | ||
|
||
|
||
class CustomEventLoopPolicy(asyncio.DefaultEventLoopPolicy): | ||
pass | ||
|
||
|
||
@pytest.mark.asyncio_event_loop(policy=CustomEventLoopPolicy()) | ||
class TestUsesCustomEventLoopPolicy: | ||
@pytest.mark.asyncio | ||
async def test_uses_custom_event_loop_policy(self): | ||
assert isinstance(asyncio.get_event_loop_policy(), CustomEventLoopPolicy) |
16 changes: 16 additions & 0 deletions
16
docs/source/reference/markers/class_scoped_loop_strict_mode_example.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import asyncio | ||
|
||
import pytest | ||
|
||
|
||
@pytest.mark.asyncio_event_loop | ||
class TestClassScopedLoop: | ||
loop: asyncio.AbstractEventLoop | ||
|
||
@pytest.mark.asyncio | ||
async def test_remember_loop(self): | ||
TestClassScopedLoop.loop = asyncio.get_running_loop() | ||
|
||
@pytest.mark.asyncio | ||
async def test_this_runs_in_same_loop(self): | ||
assert asyncio.get_running_loop() is TestClassScopedLoop.loop |
18 changes: 18 additions & 0 deletions
18
docs/source/reference/markers/class_scoped_loop_with_fixture_strict_mode_example.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import asyncio | ||
|
||
import pytest | ||
|
||
import pytest_asyncio | ||
|
||
|
||
@pytest.mark.asyncio_event_loop | ||
class TestClassScopedLoop: | ||
loop: asyncio.AbstractEventLoop | ||
|
||
@pytest_asyncio.fixture | ||
async def my_fixture(self): | ||
TestClassScopedLoop.loop = asyncio.get_running_loop() | ||
|
||
@pytest.mark.asyncio | ||
async def test_runs_is_same_loop_as_fixture(self, my_fixture): | ||
assert asyncio.get_running_loop() is TestClassScopedLoop.loop |
Oops, something went wrong.