Fix code-block

This commit is contained in:
Bruno Oliveira 2023-01-27 08:04:13 -03:00
parent 6c7603c9c6
commit 81a5e92fc6
1 changed files with 9 additions and 5 deletions

View File

@ -276,23 +276,27 @@ first be escaped with ``re.escape``.
Some examples:
.. code-block: python
.. code-block:: pycon
>>> with warns(UserWarning, match='must be 0 or None'):
>>> with warns(UserWarning, match="must be 0 or None"):
... warnings.warn("value must be 0 or None", UserWarning)
...
>>> with warns(UserWarning, match=r'must be \d+$'):
>>> with warns(UserWarning, match=r"must be \d+$"):
... warnings.warn("value must be 42", UserWarning)
...
>>> with warns(UserWarning, match=r'must be \d+$'):
>>> with warns(UserWarning, match=r"must be \d+$"):
... warnings.warn("this is not here", UserWarning)
...
Traceback (most recent call last):
...
Failed: DID NOT WARN. No warnings of type ...UserWarning... were emitted...
>>> with warns(UserWarning, match=re.escape('issue with foo() func')):
>>> with warns(UserWarning, match=re.escape("issue with foo() func")):
... warnings.warn("issue with foo() func")
...
You can also call :func:`pytest.warns` on a function or code string: