I am using asynctest and I want to leverage pytest fixture. I'm intersted by (but not only) the caplog fixture.
In an asynctest testing class, I can use with self.assertLogs(): but this is not sufficient when my logs are not produced within the block.
import asyncio
import logging
import asynctest
async def worker():
logging.error(":(")
class TestClass(asynctest.TestCase):
"""Testing class. """
async def setUp(self):
self.worker_task = asyncio.ensure_future(worker())
async def tearDown(self):
try:
self.worker_task.cancel()
except asyncio.CancelledError:
pass
async def test_get_error_log(self):
""" Simple test that assert logs emitted. """
with self.assertLogs(level="ERROR") as cm:
await asyncio.sleep(1)
The test above if failing but if I have:
---------- Captured log call -----------
ERROR root:tmp.py:7 :(
Aucun commentaire:
Enregistrer un commentaire