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

unittest.mock.Mock should not allow you to use non-existent assert methods #65437

voidspace opened this issue Apr 15, 2014 · 7 comments
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error


Copy link

BPO 21238
Nosy @voidspace, @dimaqq, @kushaldas
  • issue21238.patch: Patch with docs and test changes.
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = ''
    closed_at = <Date 2014-04-16.18:06:58.274>
    created_at = <Date 2014-04-15.15:51:18.917>
    labels = ['type-bug', 'library']
    title = 'unittest.mock.Mock should not allow you to use non-existent assert methods'
    updated_at = <Date 2015-07-16.22:51:51.947>
    user = '' fields:

    activity = <Date 2015-07-16.22:51:51.947>
    actor = 'John Allison'
    assignee = 'michael.foord'
    closed = True
    closed_date = <Date 2014-04-16.18:06:58.274>
    closer = 'python-dev'
    components = ['Library (Lib)']
    creation = <Date 2014-04-15.15:51:18.917>
    creator = 'michael.foord'
    dependencies = []
    files = ['34912']
    hgrepos = []
    issue_num = 21238
    keywords = ['patch']
    message_count = 7.0
    messages = ['216320', '216481', '216518', '216534', '246689', '246690', '246836']
    nosy_count = 5.0
    nosy_names = ['michael.foord', 'python-dev', 'Dima.Tisnek', 'kushal.das', 'John Allison']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = ''
    versions = ['Python 3.5']

    Copy link
    Contributor Author

    A common problem with unittest.mock.Mock is to mistype an assert method. Because mocks create attributes on demand your test will pass without error.

    We should raise an AttributeError if you access any attribute name (that doesn't exist) starting with assert or assret. There should also be a keyword argument allowing you to get the old behaviour if you need it (but this new feature should be on by default).

    Will also need docs.

    @voidspace voidspace self-assigned this Apr 15, 2014
    @voidspace voidspace added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Apr 15, 2014
    Copy link

    Patch with docs and test changes.

    Copy link
    Contributor Author

    It needs a NEWS entry, but looks good to me.

    Copy link

    python-dev mannequin commented Apr 16, 2014

    New changeset e4ee0b15cc4f by Kushal Das in branch 'default':
    Closes bpo-21238: New keyword argument unsafe to Mock.

    @python-dev python-dev mannequin closed this as completed Apr 16, 2014
    Copy link

    dimaqq mannequin commented Jul 13, 2015

    What is this **assret** spelling?

    I can't a reference to this spelling anywhere else in the codebase, let alone any docs other that this special kwarg.

    It seems intentional.

    Was that a joke?
    Or something I should know?

    Copy link

    It is a typing mistake many people make. We just want to catch those as otherwise mock will silently pass those.

    Copy link

    JohnAllison mannequin commented Jul 16, 2015

    That probably IS a joke. Why not fix the underlying issue instead?

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    None yet

    No branches or pull requests

    2 participants