On Nov 28, 2022, at 11:01 PM, Dalba <dalba.wiki@gmail.com> wrote:That does not look like a fair comparison. In `test_ip` you are tryign to get the xxyyzz attribute of the mock object itself, but in `test_site` you're accessing the attribute on the instance of the mock.I think one of the assertions needs to be changed. Either change ` assert site.xxyyzz ` to ` assert mock_Site.xxyyzz ` or ` assert mock_IPv4Address.xxyyzz ` to ` assert ip.xxyyzz `._______________________________________________On Tue, Nov 29, 2022 at 5:19 AM Roy Smith <roy@panix.com> wrote:_______________________________________________I've got:platform darwin -- Python 3.9.13, pytest-7.2.0, pluggy-1.0.0rootdir: /Users/roy/dev/dyk-tools, configfile: src/pages/pytest.iniplugins: mock-3.10.0, socket-0.5.1When I run the following:def test_ip(mocker):mock_IPv4Address = mocker.patch('ipaddress.IPv4Address', autospec=True)ip = mock_IPv4Address('1.2.3.4')assert mock_IPv4Address.xxyyzzdef test_site(mocker):mock_Site = mocker.patch('pywikibot.Site', autospec=True)site = mock_Site('en', 'wikipedia')assert site.xxyyzztest_ip() fails, as I expect it to, with AttributeError: Mock object has no attribute 'xxyyzz'. But, test_site() passes. WTF? Why does it not also fail with the same error?
pywikibot mailing list -- pywikibot@lists.wikimedia.org
To unsubscribe send an email to pywikibot-leave@lists.wikimedia.org
pywikibot mailing list -- pywikibot@lists.wikimedia.org
To unsubscribe send an email to pywikibot-leave@lists.wikimedia.org