From 6d7a45b207b6ca6372f26f96e331a3eb8af6ff7a Mon Sep 17 00:00:00 2001 From: Jasper Spaans Date: Thu, 24 Oct 2024 16:48:19 +0200 Subject: [PATCH] fix: explicitly export the items in the falcon.testing namespace (#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. --- docs/_newsfragments/2387.misc.rst | 7 +++++ falcon/testing/__init__.py | 46 ++++++++++++++++++++++++++++++- 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 docs/_newsfragments/2387.misc.rst diff --git a/docs/_newsfragments/2387.misc.rst b/docs/_newsfragments/2387.misc.rst new file mode 100644 index 000000000..0aa219996 --- /dev/null +++ b/docs/_newsfragments/2387.misc.rst @@ -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. diff --git a/falcon/testing/__init__.py b/falcon/testing/__init__.py index cfbf771a0..7d55fbf8d 100644 --- a/falcon/testing/__init__.py +++ b/falcon/testing/__init__.py @@ -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