"Fix" test_get_bin_path by changing mock order (#67730)

pytest-mock 2.0.0, when run locally, gets grumpy when os.path.exists is
messed with and then another method is patched afterwards. Likely
something in the pytest-mock chain uses os.path.exists internally, and
since pytest-mock prohibits context-specific patching, there's not a
good solution. For now, just patch os.path.exists last.

Signed-off-by: Rick Elrod <rick@elrod.me>
This commit is contained in:
Rick Elrod 2020-02-28 09:39:27 -06:00 committed by GitHub
parent 735ea43aeb
commit ed37efb217
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -15,10 +15,16 @@ def test_get_bin_path(mocker):
mocker.patch.dict('os.environ', {'PATH': path}) mocker.patch.dict('os.environ', {'PATH': path})
mocker.patch('os.pathsep', ':') mocker.patch('os.pathsep', ':')
mocker.patch('os.path.exists', side_effect=[False, True])
mocker.patch('os.path.isdir', return_value=False) mocker.patch('os.path.isdir', return_value=False)
mocker.patch('ansible.module_utils.common.process.is_executable', return_value=True) mocker.patch('ansible.module_utils.common.process.is_executable', return_value=True)
# pytest-mock 2.0.0 will throw when os.path.exists is messed with
# and then another method is patched afterwards. Likely
# something in the pytest-mock chain uses os.path.exists internally, and
# since pytest-mock prohibits context-specific patching, there's not a
# good solution. For now, just patch os.path.exists last.
mocker.patch('os.path.exists', side_effect=[False, True])
assert '/usr/local/bin/notacommand' == get_bin_path('notacommand') assert '/usr/local/bin/notacommand' == get_bin_path('notacommand')