Skip to content

Commit

Permalink
fix: explicitly export the items in the falcon.testing namespace (fal…
Browse files Browse the repository at this point in the history
…conry#2388)

* fix: explicitly export the items in the falcon.testing namespace

... so mypy also likes it when falcon.testing.TestClient is used

* chore: update __init__.py

* refactor: change `__all__` to tuple

There is no right or wrong here, just we used tuples elsewhere.
  • Loading branch information
jap authored Oct 24, 2024
1 parent 4d04e9b commit 6d7a45b
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
7 changes: 7 additions & 0 deletions docs/_newsfragments/2387.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Running mypy on code that uses parts of ``falcon.testing`` naively
would lead to errors like::

Name "falcon.testing.TestClient" is not defined

This has been fixed by explicitly exporting the names that are
imported in the ``falcon.testing`` namespace.
46 changes: 45 additions & 1 deletion falcon/testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,50 @@ def test_get_message(client):
from falcon.testing.srmock import StartResponseMock
from falcon.testing.test_case import TestCase

__all__ = (
# client
'ASGIConductor',
'Cookie',
'Result',
'ResultBodyStream',
'simulate_delete',
'simulate_get',
'simulate_head',
'simulate_options',
'simulate_patch',
'simulate_post',
'simulate_put',
'simulate_request',
'StreamedResult',
'TestClient',
# helpers
'ASGILifespanEventEmitter',
'ASGIRequestEventEmitter',
'ASGIResponseEventCollector',
'ASGIWebSocketSimulator',
'closed_wsgi_iterable',
'create_asgi_req',
'create_environ',
'create_req',
'create_scope',
'create_scofrom_headers',
'get_unused_port',
'rand_string',
'redirected',
# resource
'capture_responder_args',
'capture_responder_args_async',
'set_resp_defaults',
'set_resp_defaults_async',
'SimpleTestResource',
'SimpleTestResourceAsync',
# srmock
'StartResponseMock',
# test_case
'TestCase',
)


# NOTE(kgriffs): Alias for backwards-compatibility with Falcon 0.2
# TODO: remove in falcon 4
# TODO(vytas): Remove in Falcon 5.0.
httpnow = _util.http_now

0 comments on commit 6d7a45b

Please sign in to comment.