mautrix / telegram

A Matrix-Telegram hybrid puppeting/relaybot bridge
https://matrix.to/#/#telegram:maunium.net
GNU Affero General Public License v3.0
1.33k stars 174 forks source link

ERROR on collecting tests (import matrix.bridge.commands.handler) #625

Closed mcepl closed 2 years ago

mcepl commented 3 years ago

When trying to package mautrix-telegram for openSUSE (using mautrix-python 0.9.3 and mautrix-telegram from the commit 5ed09ad), I get this complete disaster when trying to run the test suite (apparently related to #407 ;)):

[   30s] + pytest-3.6 --ignore=_build.python36 --ignore=_build.python39 --ignore=_build.python38 -v
[   31s] ============================= test session starts ==============================
[   31s] platform linux -- Python 3.6.13, pytest-6.2.4, py-1.10.0, pluggy-0.13.1 -- /usr/bin/python3.6
[   31s] cachedir: .pytest_cache
[   31s] rootdir: /home/abuild/rpmbuild/BUILD/mautrix-telegram-0.9.0+git.1623329052.5ed09ad
[   31s] plugins: asyncio-0.14.0, mock-3.1.1
[   31s] collecting ... collected 0 items / 1 error
[   31s]
[   31s] ==================================== ERRORS ====================================
[   31s] _______________ ERROR collecting tests/commands/test_handler.py ________________
[   31s] tests/commands/test_handler.py:9: in <module>
[   31s]     import mautrix.bridge.commands.handler
[   31s] /usr/lib/python3.6/site-packages/mautrix/bridge/__init__.py:2: in <module>
[   31s]     from .custom_puppet import CustomPuppetMixin, CustomPuppetError, OnlyLoginSelf, InvalidAccessToken
[   31s] /usr/lib/python3.6/site-packages/mautrix/bridge/custom_puppet.py:21: in <module>
[   31s]     from mautrix.appservice import AppService, IntentAPI
[   31s] /usr/lib/python3.6/site-packages/mautrix/appservice/__init__.py:2: in <module>
[   31s]     from .appservice import AppService
[   31s] /usr/lib/python3.6/site-packages/mautrix/appservice/appservice.py:16: in <module>
[   31s]     from .api import AppServiceAPI, IntentAPI
[   31s] /usr/lib/python3.6/site-packages/mautrix/appservice/api/__init__.py:1: in <module>
[   31s]     from .appservice import AppServiceAPI, ChildAppServiceAPI
[   31s] /usr/lib/python3.6/site-packages/mautrix/appservice/api/appservice.py:14: in <module>
[   31s]     from mautrix.api import HTTPAPI, Method, PathBuilder
[   31s] /usr/lib/python3.6/site-packages/mautrix/api.py:125: in <module>
[   31s]     class HTTPAPI:
[   31s] /usr/lib/python3.6/site-packages/mautrix/api.py:213: in HTTPAPI
[   31s]     retry_count: Optional[int] = None) -> 'JSON':
[   31s] E   TypeError: 'type' object is not subscriptable
[   31s] =========================== short test summary info ============================
[   31s] ERROR tests/commands/test_handler.py - TypeError: 'type' object is not subscr...
[   31s] !!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
[   31s] =============================== 1 error in 0.48s ===============================

Complete build log with all details of packages used, steps taken, etc.

Raven24 commented 3 years ago

I get the same result: I updated my pip install from master in a python virtualenv just now and when I tried to run the alembic upgrade, I get a similar error with backtrace:

$ alembic upgrade head
Traceback (most recent call last):
  File "/opt/mautrix-telegram/bin/alembic", line 10, in <module>
    sys.exit(main())
  File "/opt/mautrix-telegram/lib/python3.7/site-packages/alembic/config.py", line 540, in main
    CommandLine(prog=prog).main(argv=argv)
  File "/opt/mautrix-telegram/lib/python3.7/site-packages/alembic/config.py", line 534, in main
    self.run_cmd(cfg, options)
  File "/opt/mautrix-telegram/lib/python3.7/site-packages/alembic/config.py", line 514, in run_cmd
    **dict((k, getattr(options, k, None)) for k in kwarg)
  File "/opt/mautrix-telegram/lib/python3.7/site-packages/alembic/command.py", line 279, in upgrade
    script.run_env()
  File "/opt/mautrix-telegram/lib/python3.7/site-packages/alembic/script/base.py", line 475, in run_env
    util.load_python_file(self.dir, "env.py")
  File "/opt/mautrix-telegram/lib/python3.7/site-packages/alembic/util/pyfiles.py", line 98, in load_python_file
    module = load_module_py(module_id, path)
  File "/opt/mautrix-telegram/lib/python3.7/site-packages/alembic/util/compat.py", line 174, in load_module_py
    spec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "alembic/env.py", line 11, in <module>
    import mautrix_telegram.db
  File "/opt/mautrix-telegram/lib/python3.7/site-packages/mautrix_telegram/db/__init__.py", line 18, in <module>
    from mautrix.client.state_store.sqlalchemy import UserProfile, RoomState
  File "/opt/mautrix-telegram/lib/python3.7/site-packages/mautrix/client/__init__.py", line 1, in <module>
    from .api import ClientAPI
  File "/opt/mautrix-telegram/lib/python3.7/site-packages/mautrix/client/api/__init__.py", line 6, in <module>
    from .client import ClientAPI
  File "/opt/mautrix-telegram/lib/python3.7/site-packages/mautrix/client/api/client.py", line 6, in <module>
    from .authentication import ClientAuthenticationMethods
  File "/opt/mautrix-telegram/lib/python3.7/site-packages/mautrix/client/api/authentication.py", line 9, in <module>
    from mautrix.api import Method, Path
  File "/opt/mautrix-telegram/lib/python3.7/site-packages/mautrix/api.py", line 127, in <module>
    class HTTPAPI:
  File "/opt/mautrix-telegram/lib/python3.7/site-packages/mautrix/api.py", line 215, in HTTPAPI
    retry_count: Optional[int] = None) -> 'JSON':
TypeError: 'type' object is not subscriptable
tulir commented 3 years ago

Python 3.6 is not supported and it doesn't seem to happen on 3.7.10

Raven24 commented 3 years ago

I'm on Debian 10 (Buster), the distro packages provide Python 3.7

$ python -V
Python 3.7.4

I'll see, if I can update it to a more recent version and if that fixes the issue.

tulir commented 3 years ago

I can't reproduce it on a debian 10 docker image with python 3.7.3 either, so I'd guess there's something messed up in your environment. (why do you have 3.7.4 when the debian package is 3.7.3? :thinking:)

mcepl commented 3 years ago

After switching off Python 3.6 I have just partially improved result. Now it errors with:

[   26s] ________________ ERROR at setup of TestCommandEvent.test_reply _________________
[   26s]
[   26s] context = <mautrix_telegram.context.Context object at 0x7f78e7468400>
[   26s]
[   26s]     @pytest.fixture
[   26s]     def command_processor(context: Context) -> CommandProcessor:
[   26s]         """Returns a mocked CommandProcessor."""
[   26s] >       return CommandProcessor(context)
[   26s]
[   26s] tests/commands/test_handler.py:35:
[   26s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
[   26s] mautrix_telegram/commands/handler.py:113: in __init__
[   26s]     super().__init__(event_class=CommandEvent, bridge=context.bridge)
[   26s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
[   26s]
[   26s] self = <mautrix_telegram.commands.handler.CommandProcessor object at 0x7f78e7468040>
[   26s] bridge = <Mock id='140157252963776'>
[   26s] event_class = <class 'mautrix_telegram.commands.handler.CommandEvent'>
[   26s]
[   26s]     def __init__(self, bridge: 'Bridge', event_class: Type[CommandEvent] = CommandEvent) -> None:
[   26s]         self.az = bridge.az
[   26s]         self.config = bridge.config
[   26s]         self.loop = bridge.loop or asyncio.get_event_loop()
[   26s] >       self.command_prefix = self.config["bridge.command_prefix"]
[   26s] E       TypeError: 'Mock' object is not subscriptable
[   26s]
[   26s] /usr/lib/python3.9/site-packages/mautrix/bridge/commands/handler.py:340: TypeError

Complete log again.

Raven24 commented 3 years ago

I reset the virtualenv with virtualenv --clear -p /usr/bin/python3 . After that I re-ran the pip install from git and the alembic upgrade finished without error and I was able to start the bridge again. So, yeah, something was screwed up in my environment.

mcepl commented 3 years ago

I am obviously building in completely free and fresh environment (chrooted from the rest of the system), so screwed up environment shouldn't be a problem.

tulir commented 2 years ago

Tests have been permanently fixed now (i.e. removed)