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

Remove test client #2009

Merged
merged 6 commits into from
Jan 28, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions sanic/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
serve_multiple,
)
from sanic.static import register as static_register
from sanic.testing import SanicASGITestClient, SanicTestClient
from sanic.views import CompositionView
from sanic.websocket import ConnectionClosed, WebSocketProtocol

Expand Down Expand Up @@ -87,6 +86,8 @@ def __init__(
self.websocket_tasks: Set[Future] = set()
self.named_request_middleware: Dict[str, MiddlewareType] = {}
self.named_response_middleware: Dict[str, MiddlewareType] = {}
self._test_client = None
self._asgi_client = None
# Register alternative method names
self.go_fast = self.run

Expand Down Expand Up @@ -1032,11 +1033,21 @@ async def handle_request(self, request):

@property
def test_client(self):
return SanicTestClient(self)
if self._test_client:
return self._test_client
from sanic_testing.testing import SanicTestClient

self._test_client = SanicTestClient(self)
return self._test_client

@property
def asgi_client(self):
return SanicASGITestClient(self)
if self._asgi_client:
return self._asgi_client
from sanic_testing.testing import SanicASGITestClient

self._asgi_client = SanicASGITestClient(self)
return self._asgi_client

# -------------------------------------------------------------------- #
# Execution
Expand Down
284 changes: 0 additions & 284 deletions sanic/testing.py

This file was deleted.

3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,14 @@ def open_local(paths, mode="r", encoding="utf8"):
"aiofiles>=0.6.0",
"websockets>=8.1,<9.0",
"multidict>=5.0,<6.0",
"httpx==0.15.4",
]

tests_require = [
"sanic-testing",
"pytest==5.2.1",
"multidict>=5.0,<6.0",
"gunicorn==20.0.4",
"pytest-cov",
"httpcore==0.11.*",
"beautifulsoup4",
uvloop,
ujson,
Expand Down
8 changes: 6 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import pytest

from sanic_testing import TestManager

from sanic import Sanic
from sanic.router import RouteExists, Router

Expand Down Expand Up @@ -127,6 +129,8 @@ def url_param_generator():
return TYPE_TO_GENERATOR_MAP


@pytest.fixture
@pytest.fixture(scope="function")
def app(request):
return Sanic(request.node.name)
app = Sanic(request.node.name)
# TestManager(app)
return app
5 changes: 0 additions & 5 deletions tests/test_asgi_client.py

This file was deleted.

3 changes: 2 additions & 1 deletion tests/test_keep_alive_timeout.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
import httpx
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove httpx from here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe at some point, but I don't think we are there yet. We really need a new way to test timeouts. I think I have an idea, but there are higher priorities that are on my list to accomplish before the next release.

With that said, if anyone wants to take on these tests, I would be happy to help.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a problem in using third-party requirements on our testing, since they are actually required in our own testing package, unless we remove httpx from sanic_testing in the future.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant that I really don't like the tests themselves that require us to hack httpx here. I have no intention of removing httpx from the testing client because the ASGI reach in is awesome.

import pytest

from sanic_testing.testing import HOST, SanicTestClient

from sanic import Sanic, server
from sanic.compat import OS_IS_WINDOWS
from sanic.response import text
from sanic.testing import HOST, SanicTestClient


CONFIG_FOR_TESTS = {"KEEP_ALIVE_TIMEOUT": 2, "KEEP_ALIVE": True}
Expand Down
3 changes: 2 additions & 1 deletion tests/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@

import pytest

from sanic_testing.testing import SanicTestClient

import sanic

from sanic import Sanic
from sanic.compat import OS_IS_WINDOWS
from sanic.log import LOGGING_CONFIG_DEFAULTS, logger
from sanic.response import text
from sanic.testing import SanicTestClient


logging_format = """module: %(module)s; \
Expand Down
Loading