Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn instead of raising exception in context manager #221

Merged
merged 6 commits into from Jan 4, 2021

Commits on Dec 22, 2020

  1. Warn when a mock is used as a context manager

    Instead of raising an exception, warn when a pytest-mock mock is used as
    a context manager. This lets pytest-mock mock objects that are used as
    context managers, like threading.Lock, while still letting users know
    that mocks returned from pytest-mock do not need their __enter__ method
    called to take effect.
    
    Create a PytestMockWarning class so that the warning is easy to
    pinpoint and handle.
    iforapsy committed Dec 22, 2020
    Copy the full SHA
    c33a300 View commit details
    Browse the repository at this point in the history
  2. Update unit tests for context manager warnings

    Test that warnings are issued when mocks are used as context manager.
    Verify that the warnings have the expected message and that they point
    to the correct code.
    iforapsy committed Dec 22, 2020
    Copy the full SHA
    e40e97c View commit details
    Browse the repository at this point in the history
  3. Fix stacklevel for Python 3.8 and higher

    Use a stacklevel=5 for Python 3.8 and up so that the emitted warning
    points to the correct line of code. At stacklevel=4, it was incorrectly
    pointing to code in the standard library.
    iforapsy committed Dec 22, 2020
    Copy the full SHA
    3220c96 View commit details
    Browse the repository at this point in the history

Commits on Dec 24, 2020

  1. Make context manager warning more detailed

    Make the warning message when a mock is used as a context manager more
    detailed. In the message, describe the use case to avoid and when the
    warning can be safely ignored.
    iforapsy committed Dec 24, 2020
    Copy the full SHA
    45d8a20 View commit details
    Browse the repository at this point in the history
  2. Create patch.context_manager method

    Create patch.context_manager method that allows the patched object to be
    used as a context manager without issuing a warning on __enter__.
    Otherwise, the method is functionally equivalent to patch.object.
    iforapsy committed Dec 24, 2020
    Copy the full SHA
    838d384 View commit details
    Browse the repository at this point in the history

Commits on Jan 4, 2021

  1. Fix linting

    nicoddemus committed Jan 4, 2021
    Copy the full SHA
    5840235 View commit details
    Browse the repository at this point in the history