Skip to content

Commit

Permalink
Refactor and Overhaul test_official (#4087)
Browse files Browse the repository at this point in the history
  • Loading branch information
harshil21 committed Feb 9, 2024
1 parent 680dc2b commit 1cf63c2
Show file tree
Hide file tree
Showing 13 changed files with 878 additions and 610 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test_official.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
python -W ignore -m pip install -r requirements-dev.txt
- name: Compare to official api
run: |
pytest -v tests/test_official.py --junit-xml=.test_report_official.xml
pytest -v tests/test_official/test_official.py --junit-xml=.test_report_official.xml
exit $?
env:
TEST_OFFICIAL: "true"
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ markers = [
"req",
]
asyncio_mode = "auto"
log_format = "%(funcName)s - Line %(lineno)d - %(message)s"
# log_level = "DEBUG" # uncomment to see DEBUG logs

# MYPY:
[tool.mypy]
Expand Down
12 changes: 6 additions & 6 deletions telegram/_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6138,8 +6138,8 @@ async def get_custom_emoji_stickers(
async def upload_sticker_file(
self,
user_id: int,
sticker: Optional[FileInput],
sticker_format: Optional[str],
sticker: FileInput,
sticker_format: str,
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
Expand Down Expand Up @@ -6180,7 +6180,7 @@ async def upload_sticker_file(
"""
data: JSONDict = {
"user_id": user_id,
"sticker": self._parse_file_input(sticker), # type: ignore[arg-type]
"sticker": self._parse_file_input(sticker),
"sticker_format": sticker_format,
}
result = await self._post(
Expand All @@ -6199,7 +6199,7 @@ async def add_sticker_to_set(
self,
user_id: int,
name: str,
sticker: Optional["InputSticker"],
sticker: "InputSticker",
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
Expand Down Expand Up @@ -6298,8 +6298,8 @@ async def create_new_sticker_set(
user_id: int,
name: str,
title: str,
stickers: Optional[Sequence["InputSticker"]],
sticker_format: Optional[str],
stickers: Sequence["InputSticker"],
sticker_format: str,
sticker_type: Optional[str] = None,
needs_repainting: Optional[bool] = None,
*,
Expand Down
10 changes: 5 additions & 5 deletions telegram/ext/_extbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ async def add_sticker_to_set(
self,
user_id: int,
name: str,
sticker: Optional["InputSticker"],
sticker: "InputSticker",
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
Expand Down Expand Up @@ -1177,8 +1177,8 @@ async def create_new_sticker_set(
user_id: int,
name: str,
title: str,
stickers: Optional[Sequence["InputSticker"]],
sticker_format: Optional[str],
stickers: Sequence["InputSticker"],
sticker_format: str,
sticker_type: Optional[str] = None,
needs_repainting: Optional[bool] = None,
*,
Expand Down Expand Up @@ -3673,8 +3673,8 @@ async def unpin_all_general_forum_topic_messages(
async def upload_sticker_file(
self,
user_id: int,
sticker: Optional[FileInput],
sticker_format: Optional[str],
sticker: FileInput,
sticker_format: str,
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
Expand Down
11 changes: 11 additions & 0 deletions tests/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,17 @@ Use as follows:
$ pytest -m dev
Debugging tests
===============

Writing tests can be challenging, and fixing failing tests can be even more so. To help with this,
PTB has started to adopt the use of ``logging`` in the test suite. You can insert debug logging
statements in your tests to help you understand what's going on. To enable these logs, you can set
``log_level = DEBUG`` in ``setup.cfg`` or use the ``--log-level=INFO`` flag when running the tests.
If a test is large and complicated, it is recommended to leave the debug logs for others to use as
well.


Bots used in tests
==================

Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
if sys.version_info < (3, 10):
if RUN_TEST_OFFICIAL:
logging.warning("Skipping test_official.py since it requires Python 3.10+")
collect_ignore.append("test_official.py")
collect_ignore_glob = ["test_official/*.py"]


# This is here instead of in setup.cfg due to https://github.com/pytest-dev/pytest/issues/8343
Expand Down
Loading

0 comments on commit 1cf63c2

Please sign in to comment.