diff --git a/pyproject.toml b/pyproject.toml index 34c2a763798..cd69c757871 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -48,7 +48,7 @@ exclude-protected = ["_unfrozen"] # PYTEST: [tool.pytest.ini_options] testpaths = ["tests"] -addopts = "--no-success-flaky-report -rsxX" +addopts = "--no-success-flaky-report -rX" filterwarnings = [ "error", "ignore::DeprecationWarning", diff --git a/requirements-dev.txt b/requirements-dev.txt index ef0fd597a78..e5febab9c92 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,7 +1,7 @@ pre-commit # needed for pre-commit hooks in the git commit command # For the test suite -pytest==7.4.4 +pytest==8.1.1 pytest-asyncio==0.21.1 # needed because pytest doesn't come with native support for coroutines as tests pytest-xdist==3.6.0 # xdist runs tests in parallel flaky # Used for flaky tests (flaky decorator) diff --git a/telegram/_utils/enum.py b/telegram/_utils/enum.py index aa370cbd44a..20a045c02fe 100644 --- a/telegram/_utils/enum.py +++ b/telegram/_utils/enum.py @@ -60,7 +60,7 @@ def __str__(self) -> str: # Apply the __repr__ modification and __str__ fix to IntEnum -class IntEnum(_enum.IntEnum): +class IntEnum(_enum.IntEnum): # pylint: disable=invalid-slots """Helper class for int enums where ``str(member)`` prints the value, but ``repr(member)`` gives ``EnumName.MEMBER_NAME``. """ diff --git a/telegram/constants.py b/telegram/constants.py index 2eac123fc14..8bf1f9eac54 100644 --- a/telegram/constants.py +++ b/telegram/constants.py @@ -29,7 +29,7 @@ * Most of the constants in this module are grouped into enums. """ # TODO: Remove this when https://github.com/PyCQA/pylint/issues/6887 is resolved. -# pylint: disable=invalid-enum-extension +# pylint: disable=invalid-enum-extension,invalid-slots __all__ = [ "BOT_API_VERSION", diff --git a/telegram/ext/_application.py b/telegram/ext/_application.py index 94cf87764cd..fce026f9f22 100644 --- a/telegram/ext/_application.py +++ b/telegram/ext/_application.py @@ -1075,12 +1075,11 @@ def __run( loop.run_forever() except (KeyboardInterrupt, SystemExit): _LOGGER.debug("Application received stop signal. Shutting down.") - except Exception as exc: - # In case the coroutine wasn't awaited, we don't need to bother the user with a warning - updater_coroutine.close() - raise exc finally: # We arrive here either by catching the exceptions above or if the loop gets stopped + # In case the coroutine wasn't awaited, we don't need to bother the user with a warning + updater_coroutine.close() + try: # In we never got to await the coroutine, it's cleaner to close it here # This can be the case e.g. if post_init raises SystemExit diff --git a/telegram/ext/_handlers/commandhandler.py b/telegram/ext/_handlers/commandhandler.py index 94ee77493bb..814e1966074 100644 --- a/telegram/ext/_handlers/commandhandler.py +++ b/telegram/ext/_handlers/commandhandler.py @@ -152,7 +152,6 @@ def _check_correct_args(self, args: List[str]) -> Optional[bool]: Returns: :obj:`bool`: Whether the args are valid for this handler. """ - # pylint: disable=too-many-boolean-expressions return bool( (self.has_args is None) or (self.has_args is True and args) diff --git a/telegram/ext/filters.py b/telegram/ext/filters.py index 614673628e1..f2820d2b25a 100644 --- a/telegram/ext/filters.py +++ b/telegram/ext/filters.py @@ -289,7 +289,7 @@ def check_update(self, update: Update) -> Optional[Union[bool, FilterDataDict]]: :attr:`telegram.Update.edited_business_message`, or :obj:`False` otherwise. """ return bool( # Only message updates should be handled. - update.channel_post # pylint: disable=too-many-boolean-expressions + update.channel_post or update.message or update.edited_channel_post or update.edited_message diff --git a/tests/ext/test_application.py b/tests/ext/test_application.py index ca6133cf56e..d8a20284f25 100644 --- a/tests/ext/test_application.py +++ b/tests/ext/test_application.py @@ -2398,7 +2398,7 @@ def abort_app(): assert received_signals == [signal.SIGINT, signal.SIGTERM, signal.SIGABRT] received_signals.clear() - loop.call_later(0.6, abort_app) + loop.call_later(0.8, abort_app) app.run_webhook(port=49152, webhook_url="example.com", close_loop=False) if platform.system() == "Windows": diff --git a/tests/ext/test_prefixhandler.py b/tests/ext/test_prefixhandler.py index b0d75b06951..a42ec4e058e 100644 --- a/tests/ext/test_prefixhandler.py +++ b/tests/ext/test_prefixhandler.py @@ -25,7 +25,7 @@ def combinations(prefixes, commands): - return (prefix + command for prefix in prefixes for command in commands) + return [prefix + command for prefix in prefixes for command in commands] class TestPrefixHandler(BaseTest): @@ -40,31 +40,31 @@ def test_slot_behaviour(self): assert getattr(handler, attr, "err") != "err", f"got extra slot '{attr}'" assert len(mro_slots(handler)) == len(set(mro_slots(handler))), "duplicate slot" - @pytest.fixture(scope="class", params=PREFIXES) + @pytest.fixture(params=PREFIXES) def prefix(self, request): return request.param - @pytest.fixture(scope="class", params=[1, 2], ids=["single prefix", "multiple prefixes"]) + @pytest.fixture(params=[1, 2], ids=["single prefix", "multiple prefixes"]) def prefixes(self, request): return TestPrefixHandler.PREFIXES[: request.param] - @pytest.fixture(scope="class", params=COMMANDS) + @pytest.fixture(params=COMMANDS) def command(self, request): return request.param - @pytest.fixture(scope="class", params=[1, 2], ids=["single command", "multiple commands"]) + @pytest.fixture(params=[1, 2], ids=["single command", "multiple commands"]) def commands(self, request): return TestPrefixHandler.COMMANDS[: request.param] - @pytest.fixture(scope="class") + @pytest.fixture() def prefix_message_text(self, prefix, command): return prefix + command - @pytest.fixture(scope="class") + @pytest.fixture() def prefix_message(self, prefix_message_text): return make_message(prefix_message_text) - @pytest.fixture(scope="class") + @pytest.fixture() def prefix_message_update(self, prefix_message): return make_message_update(prefix_message) @@ -94,12 +94,12 @@ async def test_basic(self, app, prefix, command): assert isinstance(handler.commands, frozenset) assert handler.commands == {"#cmd", "#bmd"} - def test_single_multi_prefixes_commands(self, prefixes, commands, prefix_message_update): + def test_single_multi_prefixes_commands(self, prefix_message_update): """Test various combinations of prefixes and commands""" handler = self.make_default_handler() result = is_match(handler, prefix_message_update) - expected = prefix_message_update.message.text in combinations(prefixes, commands) - return result == expected + expected = prefix_message_update.message.text in self.COMBINATIONS + assert result == expected def test_edited(self, prefix_message): handler_edited = self.make_default_handler()