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

Testing fails with ModuleNotFoundError: No module named 'aiohttp' #1577

Closed
logileifs opened this issue May 15, 2019 · 11 comments
Closed

Testing fails with ModuleNotFoundError: No module named 'aiohttp' #1577

logileifs opened this issue May 15, 2019 · 11 comments

Comments

@logileifs
Copy link

logileifs commented May 15, 2019

Describe the bug
After installing sanic and setting up tests like in the documentation and running them sanic fails with ModuleNotFoundError: No module named 'aiohttp'.

It succeeds after installing 'aiohttp' manually

Code snippet
Just do a clean install of sanic and create a test as in the documentation and try running it.

Expected behavior
If 'aiohttp' is a hard dependency for testing it should be included when installing sanic

Environment (please complete the following information):

  • OS: Ubuntu 18.04
  • Version sanic==19.3.1

Stack trace

Traceback (most recent call last):
  File "/home/logi/.virtualenvs/lemo3.6/lib/python3.6/site-packages/sanic/testing.py", line 97, in _collect_response
    method, url, *request_args, **request_kwargs
  File "/home/logi/.virtualenvs/lemo3.6/lib/python3.6/site-packages/sanic/testing.py", line 20, in _local_request
    import aiohttp
ModuleNotFoundError: No module named 'aiohttp'
@harshanarayana
Copy link
Contributor

@logileifs Can you please add the stack trace to the bug description?

@logileifs
Copy link
Author

logileifs commented May 15, 2019

[2019-05-15 10:02:59 +0000] [8698] [INFO] Goin' Fast @ http://127.0.0.1:42101
[2019-05-15 10:02:59 +0000] [8698] [ERROR] Exception
Traceback (most recent call last):
  File "/home/logi/.virtualenvs/lemo3.6/lib/python3.6/site-packages/sanic/testing.py", line 97, in _collect_response
    method, url, *request_args, **request_kwargs
  File "/home/logi/.virtualenvs/lemo3.6/lib/python3.6/site-packages/sanic/testing.py", line 20, in _local_request
    import aiohttp
ModuleNotFoundError: No module named 'aiohttp'
[2019-05-15 10:02:59 +0000] [8698] [INFO] Starting worker [8698]
[2019-05-15 10:02:59 +0000] [8698] [INFO] Stopping worker [8698]
[2019-05-15 10:02:59 +0000] [8698] [INFO] Server Stopped

@harshanarayana
Copy link
Contributor

aiohttp is a test only package that doesn't get installed by default unless explicitly asked for.

# Install sanic with test utilities
$ pip3 install "sanic[test]"

@harshanarayana
Copy link
Contributor

@logileifs But I agree with what you mentioned under expected behavior. I think aiohttp can be moved to the default packages that get installed with sanic since we are using it with testing.py and this error feels unwarranted.

@huge-success/sanic-core-devs Any concerns moving aiohttp to the default packages installed?

@logileifs
Copy link
Author

aiohttp is a test only package that doesn't get installed by default unless explicitly asked for.

# Install sanic with test utilities
$ pip3 install "sanic[test]"

Is this documented anywhere? I believe I've read the documentation rather well and I don't recall seeing anywhere mentioned that sanic provides any extra packages

@harshanarayana
Copy link
Contributor

harshanarayana commented May 15, 2019

@logileifs There is a reference for this under the Contributing section. But the command used in that context is a bit different since it installs sanic from a cloned path. pip install -e ".[test]"

@ahopkins
Copy link
Member

aiohttp has been removed as of #1562. Instead, we have migrated to requests-async. The reason is primarily to support our development towards ASGI support (See #1475).

I do not think we should include it in the standard install because it is an extra dependency that is not needed. However, on the flip side, I think having pip3 install "sanic[test]" be documented is definitely worth doing to let people know that it is probably what they want in dev.

I also would highly push developers towards: https://github.com/yunstanford/pytest-sanic.

@logileifs
Copy link
Author

logileifs commented May 15, 2019

I do not think we should include it in the standard install because it is an extra dependency that is not needed.

I disagree with you there @ahopkins, to develop a web application you need to be able to test it, to test it you apparently need aiohttp or requests-async so those dependencies should absolutely be included in the main package.

I've tried many different web frameworks and don't remember any single one of them requiring you to install some extra dependencies just for testing. I think that is a very weird and untrustworthy approach, makes it seem like testing is an afterthought

@ahopkins
Copy link
Member

ahopkins commented May 15, 2019

@logileifs In this case, then, your build packages and containers become bloated with unused code and unused dependencies.

I am not saying it has to be this way, but that this is the decision that was made: favor speed and making things lean. Indeed, there are plenty of ways to test Sanic applications that do not require using the SanicTestClient. The main purpose there is to support the testing and development of the application.

@logileifs
Copy link
Author

@ahopkins fair enough

@harshanarayana
Copy link
Contributor

@logileifs aiohttp or requests-async are used as a dependency in sanic code as a way to test the sanic itself.

If you are testing your own service written using sanic then pytest-sanic might be a more suitable way to perform your testing and that should install all the dependencies required to run the UTs and any other form of tests.

@ahopkins You are right. Now that I think about it again after reading your comments, it should be enough to document this rather than moving it to the default list of dependencies installed. Thanks for pointing me in the right direction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants