PyUtilib / pyutilib

A collection of general Python utilities, including logging and file IO, subprocess management, plugin systems, and workflow management.
BSD 3-Clause "New" or "Revised" License
34 stars 20 forks source link

Add `unittest.mock` backport #98

Closed ruaridhw closed 4 years ago

ruaridhw commented 4 years ago

Fixes:

Summary/Motivation:

Changes proposed in this PR:

-

Legal Acknowledgement

By contributing to this software project, I agree to the following terms and conditions for my contribution:

  1. I agree my contributions are submitted under the BSD license.
  2. I represent I am authorized to make the contributions and grant the license. If my employer has rights to intellectual property that includes these contributions, I represent that I have received permission to make contributions and grant the required license on behalf of that employer.
jsiirola commented 4 years ago

It looks like the hard dependence on the mock library might be causing problems (I rarely use mock, and in our other discussion missed that mock was a separate package before Python 3.3). I am not sure how others will feel about adding another dependency. At a minimum, we should promulgate the mock from unittest in Python3:

if six.PY3:
    from unittest import mock
else:
    import mock

I wonder if it also makes sense to make the dependency optional:

if six.PY3:
    from unittest import mock
    mock_available = True
else:
    try:
        import mock
        mock_available = True
    except ImportError:
        mock_available = False

Thoughts?

ruaridhw commented 4 years ago

Updated accordingly though I figured that using Python3 doesn't necessarily imply that mock exists in unittest since it wasn't around in 3.0

jsiirola commented 4 years ago

@ruaridhw: correct, but PyUtilib explicitly doesn't support 3.0-3.3, so we can be lazy.

coveralls commented 4 years ago

Coverage Status

Coverage decreased (-0.01%) to 61.919% when pulling ceada22944805c270f389d83f49f3e10aee67b8d on flexciton:feat/mock into 6f02a998a57f1e843dcde3409fad58cd15005c43 on PyUtilib:master.