Azure / WALinuxAgent

Microsoft Azure Linux Guest Agent
http://azure.microsoft.com/
Apache License 2.0
543 stars 372 forks source link

workaround for python3.5 UTs build setup and replace assert_called_once mock method #3191

Closed nagworld9 closed 3 months ago

nagworld9 commented 3 months ago

Description

Python3.5 setup fails with invalid ssl cert while fetching pip ( Could not fetch URL https://pypi.python.org/simple/pip/: There was a problem confirming the ssl certificate: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:728) - skipping) Added workaround for it as mentioned on this thread https://github.com/actions/setup-python/issues/866

This pr also addresses some of the unit tests failing on python3.5 due to assert_called_once attribute not found error and same thing, we saw it in container as well

    mock_stream.assert_called_once()
  File "/usr/lib/python3.5/unittest/mock.py", line 583, in __getattr__
    raise AttributeError(name)
AttributeError: assert_called_once

I found out that assert_called_once is not available before < 3.6 and using this will produce unexpected behavior. It seems we should avoid using as per this https://web.archive.org/web/20210919045841/http://engineroom.trackmaven.com/blog/mocking-mistakes/

https://web.archive.org/web/20211009193419/https://docs.python.org/3.5/library/unittest.mock.html https://stackoverflow.com/questions/42297549/magic-mock-assert-called-once-vs-assert-called-once-with-weird-behaviour

Issue #


PR information

Quality of Code and Contribution Guidelines