Just an idea but I haven’t verified: BaseSite has a __getattr__ method defined which delegates methods to its Family class. Maybe mock.patch has a side effect which leads to that behaviour you described due to this method. To verify you could comment out this method and test again.

Best
xqt

Am 29.11.2022 um 02:49 schrieb Roy Smith <roy@panix.com>:


I've got:

platform darwin -- Python 3.9.13, pytest-7.2.0, pluggy-1.0.0
rootdir: /Users/roy/dev/dyk-tools, configfile: src/pages/pytest.ini
plugins: mock-3.10.0, socket-0.5.1


When 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.xxyyzz


def test_site(mocker):
mock_Site = mocker.patch('pywikibot.Site', autospec=True)
site = mock_Site('en', 'wikipedia')
assert site.xxyyzz


test_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