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

'called_once' is not a valid assertion issues in various tests (probably Python 3.12 related) #1765

Closed
frantisekz opened this issue Jul 10, 2023 · 1 comment

Comments

@frantisekz
Copy link

Since merging of Python 3.12 into Fedora 39, apart from needing to use cached_property from pypi, the tests are failing with the following:

=================================== FAILURES ===================================
______________________ test_Hub.test_call_soon_uses_lock _______________________

self = <t.unit.asynchronous.test_hub.test_Hub object at 0x7f6b3d5572f0>

    def test_call_soon_uses_lock(self):
        callback = Mock(name='callback')
        with patch.object(self.hub, '_ready_lock', autospec=True) as lock:
            self.hub.call_soon(callback)
>           assert lock.__enter__.called_once()

t/unit/asynchronous/test_hub.py:196: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <MagicMock name='_ready_lock.__enter__' id='140098499051792'>
name = 'called_once'

    def __getattr__(self, name):
        if name in {'_mock_methods', '_mock_unsafe'}:
            raise AttributeError(name)
        elif self._mock_methods is not None:
            if name not in self._mock_methods or name in _all_magics:
                raise AttributeError("Mock object has no attribute %r" % name)
        elif _is_magic(name):
            raise AttributeError(name)
        if not self._mock_unsafe and (not self._mock_methods or name not in self._mock_methods):
            if name.startswith(('assert', 'assret', 'asert', 'aseert', 'assrt')) or name in _ATTRIB_DENY_LIST:
>               raise AttributeError(
                    f"{name!r} is not a valid assertion. Use a spec "
                    f"for the mock if {name!r} is meant to be an attribute.")
E               AttributeError: 'called_once' is not a valid assertion. Use a spec for the mock if 'called_once' is meant to be an attribute.

/usr/lib64/python3.12/unittest/mock.py:663: AttributeError
______________________ test_Hub.test__pop_ready_uses_lock ______________________

self = <t.unit.asynchronous.test_hub.test_Hub object at 0x7f6b3d595a30>

    def test__pop_ready_uses_lock(self):
        with patch.object(self.hub, '_ready_lock', autospec=True) as lock:
            self.hub._pop_ready()
>           assert lock.__enter__.called_once()

t/unit/asynchronous/test_hub.py:571: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <MagicMock name='_ready_lock.__enter__' id='140098497272800'>
name = 'called_once'

    def __getattr__(self, name):
        if name in {'_mock_methods', '_mock_unsafe'}:
            raise AttributeError(name)
        elif self._mock_methods is not None:
            if name not in self._mock_methods or name in _all_magics:
                raise AttributeError("Mock object has no attribute %r" % name)
        elif _is_magic(name):
            raise AttributeError(name)
        if not self._mock_unsafe and (not self._mock_methods or name not in self._mock_methods):
            if name.startswith(('assert', 'assret', 'asert', 'aseert', 'assrt')) or name in _ATTRIB_DENY_LIST:
>               raise AttributeError(
                    f"{name!r} is not a valid assertion. Use a spec "
                    f"for the mock if {name!r} is meant to be an attribute.")
E               AttributeError: 'called_once' is not a valid assertion. Use a spec for the mock if 'called_once' is meant to be an attribute.

/usr/lib64/python3.12/unittest/mock.py:663: AttributeError

Apart from the buildroot defaults, the following packages (in these versions) are used for the build:

  expat-2.5.0-2.fc38.x86_64                       libb2-0.98.1-8.fc38.x86_64                          mpdecimal-2.5.1-6.fc38.x86_64                           pyproject-rpm-macros-1.9.0-1.fc39.noarch       
  python-pip-wheel-23.1.2-2.fc39.noarch           python-rpm-macros-3.12-1.fc39.noarch                python3-3.12.0~b3-2.fc39.x86_64                         python3-amqp-5.1.1-5.fc39.noarch               
  python3-attrs-23.1.0-3.fc39.noarch              python3-azure-common-1:1.1.28-5.fc39.noarch         python3-azure-core-2:1.26.0-3.fc39.noarch               python3-azure-identity-1:1.10.0-8.fc39.noarch  
  python3-azure-mgmt-core-1:1.3.2-5.fc39.noarch   python3-azure-mgmt-servicebus-8.2.0-3.fc39.noarch   python3-azure-mgmt-storage-21.0.0-4.fc39.noarch         python3-boto3-1.26.164-1.fc39.noarch           
  python3-botocore-1.29.164-2.fc39.noarch         python3-brotli-1.0.9-12.fc39.x86_64                 python3-bson-4.2.0-3.fc39.x86_64                        python3-cached_property-1.5.2-10.fc39.noarch   
  python3-certifi-2022.12.07-2.fc39.noarch        python3-cffi-1.15.1-5.fc39.x86_64                   python3-charset-normalizer-3.1.0-2.fc39.noarch          python3-cryptography-40.0.2-3.fc39.x86_64      
  python3-dateutil-1:2.8.2-9.fc39.noarch          python3-devel-3.12.0~b3-2.fc39.x86_64               python3-freezegun-1.2.2-3.fc39.noarch                   python3-greenlet-2.0.2-1.fc39.x86_64           
  python3-hypothesis-6.62.1-4.fc39.noarch         python3-idna-3.4-3.fc39.noarch                      python3-iniconfig-1.1.1-13.fc39.noarch                  python3-isodate-0.6.1-8.fc39.noarch            
  python3-jmespath-1.0.1-3.fc39.noarch            python3-jwt-2.6.0-3.fc39.noarch                     python3-jwt+crypto-2.6.0-3.fc39.noarch                  python3-libs-3.12.0~b3-2.fc39.x86_64           
  python3-msal-1.20.0-3.fc39.noarch               python3-msal-extensions-1.0.0-6.fc39.noarch         python3-msrest-0.7.1-5.20221014git2d8fd04.fc39.noarch   python3-oauthlib-3.2.1-5.fc39.noarch           
  python3-packaging-23.1-3.fc39.noarch            python3-pluggy-1.0.0-8.fc39.noarch                  python3-ply-3.11-19.fc39.noarch                         python3-portalocker-2.7.0-3.fc39.noarch        
  python3-pycparser-2.20-10.fc39.noarch           python3-pycurl-7.45.2-4.fc39.x86_64                 python3-pymongo-4.2.0-3.fc39.x86_64                     python3-pyro-4.80-9.fc39.noarch                
  python3-pysocks-1.7.1-19.fc39.noarch            python3-pytest-7.3.2-3.fc39.noarch                  python3-pytest-freezegun-0.4.2-8.fc39.noarch            python3-pytz-2023.3-2.fc39.noarch              
  python3-requests-2.28.2-4.fc39.noarch           python3-requests-oauthlib-1.3.1-5.fc39.noarch       python3-rpm-generators-14-6.fc39.noarch                 python3-rpm-macros-3.12-1.fc39.noarch          
  python3-s3transfer-0.6.1-2.fc39.noarch          python3-serpent-1.40-4.fc39.noarch                  python3-setuptools-67.7.2-5.fc39.noarch                 python3-six-1.16.0-11.fc39.noarch              
  python3-sortedcontainers-2.4.0-12.fc39.noarch   python3-sqlalchemy-1.4.49-1.fc39.x86_64             python3-typing-extensions-4.7.0-2.fc39.noarch           python3-urllib3-1.26.15-3.fc39.noarch          
  python3-urllib3+socks-1.26.15-3.fc39.noarch     python3-vine-5.0.0-10.fc39.noarch 
@FrankK-1234
Copy link
Contributor

To me it looks like this pr is already resolved by issues #1812 and #1813 ? Can the issue be closed ?

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

No branches or pull requests

4 participants
@frantisekz @auvipy @FrankK-1234 and others