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

Adding _test_manager object to Sanic App prevents App from being pickled #3

Closed
ashleysommer opened this issue Jan 28, 2021 · 0 comments · Fixed by #7
Closed

Adding _test_manager object to Sanic App prevents App from being pickled #3

ashleysommer opened this issue Jan 28, 2021 · 0 comments · Fixed by #7

Comments

@ashleysommer
Copy link
Member

Example:

import pickle
from sanic import Sanic
from sanic_testing import TestManager

app = Sanic(__name__)
test_manager = TestManager(app)

my_dict = {"app": app}
my_pickled = pickle.dumps(my_dict)

Error:

>        pickle.dumps(my_dict)
E       AttributeError: Can't pickle local object 'SanicASGITestClient.__init__.<locals>._collect_request'

This is due to the use of nested functions in the ASGS TestClient methods, python does not know how to pickle object that use those.

ashleysommer added a commit to ashleysommer/sanic-testing that referenced this issue Jan 28, 2021
… weird App pickling error seen when using TestManager (specifically on the ASGITestClient)

Add logic to remove the CookieJar from ASGITestClient before pickling, then add it back when unpickled. The cookie jar contains a ThreadLock which cannot be pickled.

Fixes sanic-org#3

Improve gather_request logic in TestClient and ASGITestClient, Fixes sanic-org#4

Change "before_server_end" to "before_server_stop". Fixes sanic-org#5

Fix return type on _sanic_endpoint_test, Fixes sanic-org#6

Fixes sanic-org#6
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

Successfully merging a pull request may close this issue.

1 participant