GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — unittest.mock.seal doesn't work as expected with AsyncMock · Issue #100287 · python/cpython

unittest.mock.seal doesn't work as expected with AsyncMock #100287

New issue
Copy link
New issue
Copy link
Closed
Closed
unittest.mock.seal doesn't work as expected with AsyncMock#100287
Copy link
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@hauntsaninja
hauntsaninja
opened on Dec 16, 2022
Issue body actions

I noticed this while reviewing #100252 (comment)

I believe the following test case should pass, but it doesn't on main

import unittest
from unittest.mock import Mock, seal

class AsyncClass:
    async def async_method(self): pass
    def normal_method(self): pass

class Case(unittest.TestCase):
    def test_spec_normal_methods_on_class_with_mock_seal(self):
        mock = Mock(AsyncClass)
        seal(mock)
        # test passes, aka this raises AttributError
        with self.assertRaises(AttributeError):
            mock.normal_method
        # test fails, aka this does not raise AttributError
        with self.assertRaises(AttributeError):
            mock.async_method

unittest.main()

It's easy to fix, just need to move the clause that handles AsyncMock after the if self._mock_sealed: check.

cc @sobolevn who moved the if self._mock_sealed: check earlier in https://github.com/python/cpython/pull/28300/files , but not all the way

Linked PRs

  • gh-100287: Fix unittest.mock.seal with AsyncMock #100496
  • [3.11] gh-100287: Fix unittest.mock.seal with AsyncMock (GH-100496) #100506
  • [3.10] gh-100287: Fix unittest.mock.seal with AsyncMock (GH-100496) #100508

Activity

  1. hauntsaninja
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Dec 16, 2022
  2. sobolevn
    added
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    on Dec 16, 2022
  3. hauntsaninja
    added a commit that references this issue on Dec 24, 2022

    pythongh-100287: Fix unittest.mock.seal with AsyncMock

    9b0f3d6
  4. cjw296
    added a commit that references this issue on Dec 24, 2022

    gh-100287: Fix unittest.mock.seal with AsyncMock (#100496)

    e4b43eb
  5. hauntsaninja
    added 4 commits that reference this issue on Dec 24, 2022

    [3.11] pythongh-100287: Fix unittest.mock.seal with AsyncMock (python…

    a912701

    [3.10] pythongh-100287: Fix unittest.mock.seal with AsyncMock (python…

    31d4692

    [3.11] gh-100287: Fix unittest.mock.seal with AsyncMock (GH-100496) (#…

    75b75df

    [3.10] gh-100287: Fix unittest.mock.seal with AsyncMock (GH-100496) (#…

    9975d4e
  6. hauntsaninja
    closed this as completedon Dec 24, 2022
  7. iritkatriel
    added a commit that references this issue on Dec 28, 2022

    Merged main into regmachine branch (#50)

    fdc73cb
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

    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.