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

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

Comments

@voidspace
Copy link
Contributor

voidspace commented Apr 15, 2014

BPO 21238
Nosy @voidspace, @dimaqq, @kushaldas
Files
  • 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 = 'https://github.com/voidspace'
    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 = 'https://github.com/voidspace'

    bugs.python.org 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 = 'https://bugs.python.org/issue21238'
    versions = ['Python 3.5']

    @voidspace
    Copy link
    Contributor Author

    voidspace commented Apr 15, 2014

    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
    @kushaldas
    Copy link
    Member

    kushaldas commented Apr 16, 2014

    Patch with docs and test changes.

    @voidspace
    Copy link
    Contributor Author

    voidspace commented Apr 16, 2014

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

    @python-dev
    Copy link
    Mannequin

    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.
    http://hg.python.org/cpython/rev/e4ee0b15cc4f

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

    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?

    @kushaldas
    Copy link
    Member

    kushaldas commented Jul 13, 2015

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

    @JohnAllison
    Copy link
    Mannequin

    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
    Labels
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants