Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unittest failing with “ AttributeError: module 'typing' has no attribute 'StatusLike' ” #1496

Closed
mxjeff opened this issue Sep 8, 2024 · 1 comment

Comments

@mxjeff
Copy link

mxjeff commented Sep 8, 2024

Trying to run unittest against 13.0.1 I got an AttributeError.

I first stumble upon the issue trying to update the Debian package (python 3.12 in a chroot), but I reproduced with python 3.11 as well.

Here is what I got running python -m unittest discover (inside 13.0.1 extracted tar ball):

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/usr/lib/python3.11/unittest/__main__.py", line 18, in <module>
    main(module=None)
  File "/usr/lib/python3.11/unittest/main.py", line 101, in __init__
    self.parseArgs(argv)
  File "/usr/lib/python3.11/unittest/main.py", line 127, in parseArgs
    self._do_discovery(argv[2:])
  File "/usr/lib/python3.11/unittest/main.py", line 247, in _do_discovery
    self.createTests(from_discovery=True, Loader=Loader)
  File "/usr/lib/python3.11/unittest/main.py", line 157, in createTests
    self.test = loader.discover(self.start, self.pattern, self.top)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/unittest/loader.py", line 322, in discover
    tests = list(self._find_tests(start_dir, pattern))
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/unittest/loader.py", line 377, in _find_tests
    tests, should_recurse = self._find_test_path(full_path, pattern)
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/unittest/loader.py", line 453, in _find_test_path
    tests = self.loadTestsFromModule(package, pattern=pattern)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/unittest/loader.py", line 122, in loadTestsFromModule
    obj = getattr(module, name)
          ^^^^^^^^^^^^^^^^^^^^^
  File "/dev/shm/websockets/websockets/imports.py", line 77, in __getattr__
    return import_name(name, source, namespace)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/dev/shm/websockets/websockets/imports.py", line 28, in import_name
    return getattr(module, name)
           ^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'typing' has no attribute 'StatusLike'

Not sure I understand what is going on here, is there a typo in lazy importing?

diff --git a/src/websockets/__init__.py b/src/websockets/__init__.py
index ac02a9f..7bd35cf 100644
--- a/src/websockets/__init__.py
+++ b/src/websockets/__init__.py
@@ -183,7 +183,7 @@ else:
             "ExtensionParameter": ".typing",
             "LoggerLike": ".typing",
             "Origin": ".typing",
-            "StatusLike": "typing",
+            "StatusLike": ".typing",
             "Subprotocol": ".typing",
         },
         deprecated_aliases={

The above patch is solving the issue.

@aaugustin
Copy link
Member

aaugustin commented Sep 8, 2024

Yes, it's a typo, and I will fix it.

However, when I tried to reproduce, it only broke the convenience import from websockets import StatusLike, which websockets doesn't use internally. After applying your patch, running python -m unittest discover from the root of the repository still fails for me, just with a different error.

I suspect real reason is that websockets isn't on PYTHONPATH, or that your PYTHONPATH is somehow not correct.


For the record, the test suite is designed exclusively for the purpose of developing websockets, not for the purpose of distro packaging toolchains. I wish that you didn't run it. That would save efforts and electricity :-) Based on past discussions with distro maintainers, I expect that you won't care about my wish.

If the tests were part of my deliverables, I'd include them in the releases on PyPI. They're not, and that's why they aren't included.

Please don't engage into an extended explanation of why you trust my ability to write code and tests but not my ability to run continuous integration; or why you want to run the unit tests but not the compliance tests. I've been lectured at length before and I'm at peace with the disagreement ;-)

If you're going to run tests anyway, ideally, do so with make tests or tox -e pyXY.

aaugustin added a commit that referenced this issue Sep 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants