# pip install pytest pytest-asyncio | |
# my_module.py | |
# Create a Python module named my_module.py with a simple asynchronous function that we want to test: | |
import asyncio | |
async def async_operation(): | |
await asyncio.sleep(1) # Simulate an asynchronous operation | |
return "Async operation completed" | |
# tests/test_async_code.py | |
# In this code, we use the @pytest.mark.asyncio decorator to mark the test function as asynchronous. We then use await to call the asynchronous function async_operation and assert the expected result. | |
import pytest | |
import asyncio | |
from my_module import async_operation | |
@pytest.mark.asyncio | |
async def test_async_operation(): | |
result = await async_operation() | |
assert result == "Async operation completed" | |
# $ pytest |
I’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I am working at Cotocus. I blog tech insights at DevOps School, travel stories at Holiday Landmark, stock market tips at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at I reviewed , and SEO strategies at Wizbrand.
Please find my social handles as below;
Rajesh Kumar Personal Website
Rajesh Kumar at YOUTUBE
Rajesh Kumar at INSTAGRAM
Rajesh Kumar at X
Rajesh Kumar at FACEBOOK
Rajesh Kumar at LINKEDIN
Rajesh Kumar at PINTEREST
Rajesh Kumar at QUORA
Rajesh Kumar at WIZBRAND