From 4995bc30af9231b56a3dec46c4035d01b432c60e Mon Sep 17 00:00:00 2001 From: Dan Alvizu Date: Thu, 30 Dec 2021 15:43:12 -0700 Subject: [PATCH 1/5] Update capture-warnings.rst doc on syntax Re-order and clarify that the syntax format of pytest is the exact same as python's -W syntax --- doc/en/how-to/capture-warnings.rst | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/doc/en/how-to/capture-warnings.rst b/doc/en/how-to/capture-warnings.rst index 7e877b4d3da..71d0fe97cb1 100644 --- a/doc/en/how-to/capture-warnings.rst +++ b/doc/en/how-to/capture-warnings.rst @@ -42,8 +42,18 @@ Running pytest now produces this output: -- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html ======================= 1 passed, 1 warning in 0.12s ======================= -The ``-W`` flag can be passed to control which warnings will be displayed or even turn -them into errors: +Controlling warnings +-------------------- + +Similar to Python's `warning filter` and :option:`-W option ` flag, pytest provides +its own a ``-W`` flag to control which warnings are ignored, displayed, or turned into +errors. See the `warning filter` documentation for more +advanced use-cases. + +.. _`warning filter`: https://docs.python.org/3/library/warnings.html#warning-filter + +This code sample shows how to treat any ``UserWarning`` category class of warning +as an error: .. code-block:: pytest @@ -96,9 +106,11 @@ all other warnings into errors. When a warning matches more than one option in the list, the action for the last matching option is performed. +Syntax +------ + Both ``-W`` command-line option and ``filterwarnings`` ini option are based on Python's own -:option:`-W option ` and :func:`warnings.simplefilter`, so please refer to those sections in the Python -documentation for other examples and advanced usage. + .. _`filterwarnings`: From 3b0132a807cb6999ed555022415729b32b26e281 Mon Sep 17 00:00:00 2001 From: Dan Alvizu Date: Thu, 30 Dec 2021 15:44:22 -0700 Subject: [PATCH 2/5] Update capture-warnings.rst --- doc/en/how-to/capture-warnings.rst | 5 ----- 1 file changed, 5 deletions(-) diff --git a/doc/en/how-to/capture-warnings.rst b/doc/en/how-to/capture-warnings.rst index 71d0fe97cb1..155b63029bf 100644 --- a/doc/en/how-to/capture-warnings.rst +++ b/doc/en/how-to/capture-warnings.rst @@ -106,11 +106,6 @@ all other warnings into errors. When a warning matches more than one option in the list, the action for the last matching option is performed. -Syntax ------- - -Both ``-W`` command-line option and ``filterwarnings`` ini option are based on Python's own - .. _`filterwarnings`: From 40c49daafd2d4ffe0c007a78bfae9f8598e24d32 Mon Sep 17 00:00:00 2001 From: Dan Alvizu Date: Thu, 30 Dec 2021 19:49:40 -0700 Subject: [PATCH 3/5] Update capture-warnings.rst --- doc/en/how-to/capture-warnings.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/en/how-to/capture-warnings.rst b/doc/en/how-to/capture-warnings.rst index 155b63029bf..0656395d424 100644 --- a/doc/en/how-to/capture-warnings.rst +++ b/doc/en/how-to/capture-warnings.rst @@ -46,7 +46,7 @@ Controlling warnings -------------------- Similar to Python's `warning filter` and :option:`-W option ` flag, pytest provides -its own a ``-W`` flag to control which warnings are ignored, displayed, or turned into +its own ``-W`` flag to control which warnings are ignored, displayed, or turned into errors. See the `warning filter` documentation for more advanced use-cases. From 90a480044a080b1f3020e0ff9f26ecfe15ff5d46 Mon Sep 17 00:00:00 2001 From: Dan Alvizu Date: Mon, 3 Jan 2022 16:56:57 -0700 Subject: [PATCH 4/5] Update doc/en/how-to/capture-warnings.rst Co-authored-by: Hugo van Kemenade --- doc/en/how-to/capture-warnings.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/en/how-to/capture-warnings.rst b/doc/en/how-to/capture-warnings.rst index 0656395d424..5575c115de5 100644 --- a/doc/en/how-to/capture-warnings.rst +++ b/doc/en/how-to/capture-warnings.rst @@ -47,7 +47,7 @@ Controlling warnings Similar to Python's `warning filter` and :option:`-W option ` flag, pytest provides its own ``-W`` flag to control which warnings are ignored, displayed, or turned into -errors. See the `warning filter` documentation for more +errors. See the `warning filter_` documentation for more advanced use-cases. .. _`warning filter`: https://docs.python.org/3/library/warnings.html#warning-filter From 9d02ecbd4a620b8ab03942275f6706bd2c97e2d3 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Tue, 4 Jan 2022 10:35:41 -0300 Subject: [PATCH 5/5] Apply suggestions from code review Co-authored-by: Hugo van Kemenade --- doc/en/how-to/capture-warnings.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/en/how-to/capture-warnings.rst b/doc/en/how-to/capture-warnings.rst index 5575c115de5..efdf10e3394 100644 --- a/doc/en/how-to/capture-warnings.rst +++ b/doc/en/how-to/capture-warnings.rst @@ -45,9 +45,9 @@ Running pytest now produces this output: Controlling warnings -------------------- -Similar to Python's `warning filter` and :option:`-W option ` flag, pytest provides +Similar to Python's `warning filter`_ and :option:`-W option ` flag, pytest provides its own ``-W`` flag to control which warnings are ignored, displayed, or turned into -errors. See the `warning filter_` documentation for more +errors. See the `warning filter`_ documentation for more advanced use-cases. .. _`warning filter`: https://docs.python.org/3/library/warnings.html#warning-filter