diff --git a/pyproject.toml b/pyproject.toml index 34c2a7637..cd69c7578 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 ef0fd597a..e5febab9c 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 aa370cbd4..20a045c02 100644 --- a/telegram/_utils/enum.py +++ b/telegram/_utils/enum.py @@ -60,7 +60,7 @@ class StringEnum(str, _enum.Enum): # 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 2eac123fc..8bf1f9eac 100644 --- a/telegram/constants.py +++ b/telegram/constants.py @@ -29,7 +29,7 @@ those classes. * 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 8c32910a5..8c657d57b 100644 --- a/telegram/ext/_application.py +++ b/telegram/ext/_application.py @@ -1043,12 +1043,11 @@ class Application(Generic[BT, CCT, UD, CD, BD, JQ], AsyncContextManager["Applica 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: # Mypy doesn't know that we already check if updater is None if self.updater.running: # type: ignore[union-attr] diff --git a/telegram/ext/_handlers/commandhandler.py b/telegram/ext/_handlers/commandhandler.py index 94ee77493..814e19660 100644 --- a/telegram/ext/_handlers/commandhandler.py +++ b/telegram/ext/_handlers/commandhandler.py @@ -152,7 +152,6 @@ class CommandHandler(BaseHandler[Update, CCT]): 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 614673628..f2820d2b2 100644 --- a/telegram/ext/filters.py +++ b/telegram/ext/filters.py @@ -289,7 +289,7 @@ class BaseFilter: :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 04df44120..9057dceca 100644 --- a/tests/ext/test_application.py +++ b/tests/ext/test_application.py @@ -2297,7 +2297,7 @@ class TestApplication: 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 b0d75b069..a42ec4e05 100644 --- a/tests/ext/test_prefixhandler.py +++ b/tests/ext/test_prefixhandler.py @@ -25,7 +25,7 @@ from tests.ext.test_commandhandler import BaseTest, is_match 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 @@ class TestPrefixHandler(BaseTest): 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 @@ class TestPrefixHandler(BaseTest): 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()