Use pytest-asyncio for client and sender tests

This commit is contained in:
Lonami Exo 2023-09-01 14:02:24 +02:00
parent 294f7dedd5
commit f69e309b0b
5 changed files with 61 additions and 59 deletions

View File

@ -27,6 +27,10 @@ dynamic = ["version"]
[project.optional-dependencies]
cryptg = ["cryptg~=0.4"]
dev = [
"pytest~=7.3",
"pytest-asyncio~=0.21",
]
[project.urls]
"Homepage" = "https://telethon.dev/"

View File

@ -1,4 +1,3 @@
import asyncio
import os
import random
@ -8,8 +7,7 @@ from telethon._impl.session.message_box.defs import Session
from telethon._impl.tl.mtproto import functions, types
def test_ping_pong() -> None:
async def func() -> None:
async def test_ping_pong() -> None:
api_id = os.getenv("TG_ID")
api_hash = os.getenv("TG_HASH")
assert api_id and api_id.isdigit()
@ -33,5 +31,3 @@ def test_ping_pong() -> None:
pong = await client(functions.ping(ping_id=ping_id))
assert isinstance(pong, types.Pong)
assert pong.ping_id == ping_id
asyncio.run(func())

View File

@ -13,10 +13,9 @@ TELEGRAM_DEFAULT_TEST_DC = TELEGRAM_TEST_DC_2
TEST_TIMEOUT = 10000
def test_invoke_encrypted_method(caplog: LogCaptureFixture) -> None:
async def test_invoke_encrypted_method(caplog: LogCaptureFixture) -> None:
caplog.set_level(logging.DEBUG)
async def func() -> None:
deadline = asyncio.get_running_loop().time() + TEST_TIMEOUT
def timeout() -> float:
@ -50,5 +49,3 @@ def test_invoke_encrypted_method(caplog: LogCaptureFixture) -> None:
nearest = abcs.NearestDc.from_bytes(rx.result())
assert isinstance(nearest, types.NearestDc)
break
asyncio.run(func())

View File

@ -21,6 +21,9 @@ classifiers = [
]
dynamic = ["version"]
[project.optional-dependencies]
dev = ["pytest~=7.3"]
[project.urls]
"Homepage" = "https://telethon.dev/"
"Source" = "https://telethon.dev/code/"

2
pytest.ini Normal file
View File

@ -0,0 +1,2 @@
[pytest]
asyncio_mode = auto