From 6dc655898df34ad424dfc467a8b276fdf31bd791 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 5 Jun 2024 06:45:15 +0200 Subject: Merging upstream version 3.0.46. Signed-off-by: Daniel Baumann --- docs/pages/advanced_topics/unit_testing.rst | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'docs/pages/advanced_topics') diff --git a/docs/pages/advanced_topics/unit_testing.rst b/docs/pages/advanced_topics/unit_testing.rst index 2224bfc..02ca82d 100644 --- a/docs/pages/advanced_topics/unit_testing.rst +++ b/docs/pages/advanced_topics/unit_testing.rst @@ -116,6 +116,21 @@ single fixture that does it for every test. Something like this: with create_app_session(input=pipe_input, output=DummyOutput()): yield pipe_input +For compatibility with pytest's ``capsys`` fixture, we have to create a new +:class:`~prompt_toolkit.application.current.AppSession` for every test. This +can be done in an autouse fixture. Pytest replaces ``sys.stdout`` with a new +object in every test that uses ``capsys`` and the following will ensure that +the new :class:`~prompt_toolkit.application.current.AppSession` will each time +refer to the latest output. + +.. code:: python + + from prompt_toolkit.application import create_app_session + + @fixture(autouse=True, scope="function") + def _pt_app_session() + with create_app_session(): + yield Type checking ------------- -- cgit v1.2.3