Skip to content

Conversation

@olgarithms
Copy link
Contributor

@olgarithms olgarithms commented Jan 9, 2022

Closes #9404.

I added more context on the deprecation doc, but I have been wondering whether it would be useful to have these example on the main doc of pytest.warns(), as people might not reach the first one.

Thoughts?

@olgarithms olgarithms marked this pull request as ready for review January 9, 2022 22:15
@The-Compiler The-Compiler added the needs backport applied to PRs, indicates that it should be ported to the current bug-fix branch label Jan 11, 2022
Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @olgarithms!

Still a few last minutes adjustments left to do, please take a look. 👍

with warnings.catch_warnings():
warnings.simplefilter("ignore")
Recording warnings
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Recording warnings
.. _recwarn:
Recording warnings


.. _`recording warnings`:

.. _recwarn:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a cross-reference label referring to the Recording warnings section, so it should be kept close to it.

We should also create a new cross reference label here that can be used instead of the full URL in the changelog:

Suggested change
.. _recwarn:
.. _warns-use-cases:

Its correct usage was checking that the code emits at least one warning of any type - like ``pytest.warns()``
or ``pytest.warns(Warning)``.

See https://docs.pytest.org/en/latest/how-to/capture-warnings.html#additional-use-cases-of-warnings-in-tests for use cases.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
See https://docs.pytest.org/en/latest/how-to/capture-warnings.html#additional-use-cases-of-warnings-in-tests for use cases.
See :ref:`warns-use-cases` for examples.

Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @olgarithms!

@olgarithms olgarithms enabled auto-merge (squash) January 13, 2022 18:18
@olgarithms olgarithms merged commit 2ad1b58 into pytest-dev:main Jan 13, 2022
@olgarithms olgarithms deleted the does-not-warn branch January 13, 2022 18:33
@Zac-HD
Copy link
Member

Zac-HD commented Jan 13, 2022

Thanks @olgarithms! This is a really nice solution for a very long discussion thread 💖

@olgarithms
Copy link
Contributor Author

Thank you all for your guidance and making this far less intimidating than it was!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs backport applied to PRs, indicates that it should be ported to the current bug-fix branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Context manager to ensure no warnings are issued

4 participants