Skip to content

some way to skip replacing mock with unittest.mock #314

Closed

Description

@graingert

when you're using python 3.6 or 3.7 unittest.mock.AsyncMock is unavailable, but mock.AsyncMock is available if you're using the latest backport

there should be some way to skip replacing mock with unittest.mock, or the fixer should be moved to --py38-plus and then to a later --py...-plus as and when unittest.mock gains features

Activity

  1. asottile commented on May 26, 2020

    @asottile
    Owner

    @mxr ^ thoughts

  2. mxr commented on May 26, 2020

    @mxr
    SponsorContributor

    I suppose we could hardcode of a list of unittest.mock attrs and the version they were added into unittest.mock, and rewrite conditionally based on that

  3. asottile commented on May 26, 2020

    @asottile
    Owner

    maybe --no-mock is easier, idk

  4. mxr commented on May 26, 2020

    @mxr
    SponsorContributor

    But would you want --no-xx for suppressing an arbitrary rewrite? If not, why this specific case?

  5. asottile commented on May 26, 2020

    @asottile
    Owner

    only this case because there's a good reason to keep it (%-rewrite could break python2 in some exotic scenarios) -- unless we can actually detect it properly and then we don't need an option

  6. mxr commented on May 26, 2020

    @mxr
    SponsorContributor

    It should be possible to detect it properly using the approach I outlined

  7. graingert commented on May 26, 2020

    @graingert
    ContributorAuthor

    also mock.patch behaves differently (on 3.6/3.7 Vs pypi mock/3.8) when applied to a coroutinefunction

  8. graingert commented on May 26, 2020

    @graingert
    ContributorAuthor

    Also I don't like an autodetect because I don't want some project files using unittest.mock and others using mock

  9. graingert commented on May 26, 2020

    @graingert
    ContributorAuthor

    thirdly how should other backports be handled? eg functools32 contextlib2 pkg_util_resolve_name etc?

  10. mxr commented on May 27, 2020

    @mxr
    SponsorContributor

    Good points, sounds like --no-mock is the best approach for now

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions