From Fedora Project Wiki


Deprecate python-mock

Summary

The Package-x-generic-16.pngpython-mock (Package-x-generic-16.pngpython3-mock) package will be deprecated in Fedora 34. The package is a standard library backport for older Pythons, Fedora packages should use unittest.mock instead. Many still depend on mock, so we cannot remove it yet. Packagers are encouraged to work with upstream to switch to unittest.mock when available. A simple sed can be applied in %prep as a temporary (or even permanent) downstream solution.

Owner

Current status

  • Targeted release: Fedora 34
  • Last updated: 2021-01-18
  • FESCo issue: <will be assigned by the Wrangler>
  • Tracker bug: <will be assigned by the Wrangler>
  • Release notes tracker: <will be assigned by the Wrangler>

Detailed Description

The Package-x-generic-16.pngpython-mock package is the 3rd party backport of the standard library unittest.mock module.

> mock is now part of the Python standard library, available as unittest.mock in Python 3.3 onwards. > > This package contains a rolling backport of the standard library mock code compatible with Python 3.6 and up.

Fedora has recent enough versions of Python, hence using a library backport is redundant. Many packages only use it out of habit. We'd like to encourage both downstream packages and upstreams to switch to unittest.mock instead. Eventually, we'd like to drop Package-x-generic-16.pngpython-mock from Fedora entirely, if possible. Before we attempt to remove the package, we need to stop new packages to (Build)Require Package-x-generic-16.pngpython3-mock, hence we want to have it deprecated.

Note hat the change owner does not currently maintain Package-x-generic-16.pngpython-mock but the Python Maintenance team maintains the package in RHEL. The Fedora package maintainers have been contacted without response.

How to migrate to unittest.mock

In most cases, performing the following replacement should be enough:

s/^(\s*)import mock/\1from unittest import mock/
s/^(\s*)from mock import /\1from unittest.mock import /

If upstream really needs to support Python versions without unittest.mock, we recommend using a try-import mechanism, such as:

try:
    from unittest import mock
except ImportError:
    import mock

If dual support for unittest.mock and mock is required, and the mock package is required in the metadata (such as in the testing extras), conditionalize it, with:

mock;python_version<"3.3"

Feedback

In the past, we've managed to migrate some packages away from python-mock, without push back:

Benefit to Fedora

Scope

  • Proposal owners:
  • Other developers: N/A (not a System Wide Change)
  • Policies and guidelines: N/A (not a System Wide Change)
  • Trademark approval: N/A (not needed for this Change)
  • Alignment with Objectives:

Upgrade/compatibility impact

N/A (not a System Wide Change)

How To Test

N/A (not a System Wide Change)

User Experience

Dependencies

N/A (not a System Wide Change)

Contingency Plan

  • Contingency mechanism: (What to do? Who will do it?) N/A (not a System Wide Change)
  • Contingency deadline: N/A (not a System Wide Change)
  • Blocks release? N/A (not a System Wide Change), Yes/No
  • Blocks product? product

Documentation

N/A (not a System Wide Change)

Release Notes