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

test issues #1599

Open
0-wiz-0 opened this issue Sep 22, 2024 · 2 comments
Open

test issues #1599

0-wiz-0 opened this issue Sep 22, 2024 · 2 comments
Assignees

Comments

@0-wiz-0
Copy link

0-wiz-0 commented Sep 22, 2024

I'm packaging for pkgsrc. When running the self tests, there are some problems.

  1. Test dependencies are not documented
  2. There is a problem with using AsyncMock.
ImportError while importing test module '/scratch/security/py-google-auth/work/google_auth-2.35.0/tests/transport/aio/test_aiohttp.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/pkg/lib/python3.12/importlib/__init__.py:90: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tests/transport/aio/test_aiohttp.py:18: in <module>
    from mock import AsyncMock, Mock, patch
E   ImportError: cannot import name 'AsyncMock' from 'mock' (/usr/pkg/lib/python3.12/site-packages/mock/__init__.py)

Environment details

  • OS: NetBSD/10.99.12
  • Python version: Python 3.12.6
  • pip version: n/a
  • google-auth version: 2.35.0

Steps to reproduce

Run the self tests, see problems with missing dependencies. Most can be fixed by just adding them, but I need a patch for the asyncmock issue:

--- tests/transport/aio/test_aiohttp.py.orig    2024-09-22 16:01:57.881298857 +0000
+++ tests/transport/aio/test_aiohttp.py
@@ -15,7 +15,7 @@
 import asyncio

 from aioresponses import aioresponses  # type: ignore
-from mock import AsyncMock, Mock, patch
+from unittest.mock import AsyncMock, Mock, patch
 import pytest  # type: ignore
 import pytest_asyncio  # type: ignore

The full list of test dependencies seems to be (as of 2.35.0):

aiohttp
requests
pyu2f
aioresponses
flask
freezegun
mock
responses
test-asyncio
test-localserver
@ohmayr
Copy link
Contributor

ohmayr commented Sep 26, 2024

@0-wiz-0 thanks for reporting this. I'm unable to reproduce this error on my end when I do:

 pip install -r testing/requirements.txt
 pytest tests/transport/aio/test_aiohttp.py

I can see this error happening if you're using an older version of the mock library. I'm unsure but would appreciate it if you can share more details about your environment so I can understand what's happening.

Given that AsyncMock was introduced in unittest in python versions >3.7, it may not be an ideal solution.

I'm also curious to know if you're encountering a similar error for running tests_async/transport/test_aiohttp_requests.py which is another file where we're using AsyncMock from mock.

@0-wiz-0
Copy link
Author

0-wiz-0 commented Sep 27, 2024

Hi @ohmay, thanks for looking at this.
The problem was indeed that I had mock-3.0.5 installed. With mock-5.1.0 the patch is not needed.

That just leaves the test requirements - the sdist file on pypi does not include the testing directory.

As for the requirements themselves, can you please check if all of them are really needed?
For example, I see no difference in testing without asynctest installed, and asynctest seems to be unmaintained and not working on Python 3.11+:
Martiusweb/asynctest#163

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