blob: 4e8bc17d6d177bb9350d2562bad6348e1182bc1b [file] [log] [blame]
Jon Dufresne0f7f20f2018-09-16 18:04:59 -07001===================================
Michael Foord1e68bec2012-03-03 22:24:30 +00002 Mock - Mocking and Testing Library
Jon Dufresne0f7f20f2018-09-16 18:04:59 -07003===================================
Michael Foord1e68bec2012-03-03 22:24:30 +00004
Chris Withersb793c6a2019-04-30 09:11:06 +01005.. include:: ../README.rst
Michael Foord1e68bec2012-03-03 22:24:30 +00006
7.. module:: mock
8 :synopsis: Mock object and testing library.
9
10.. index:: introduction
11
Robert Collins18c9bbd2015-07-10 14:00:11 +120012.. toctree::
Chris Withersb793c6a2019-04-30 09:11:06 +010013 :hidden:
Robert Collins18c9bbd2015-07-10 14:00:11 +120014
15 changelog
16
Chris Withersb793c6a2019-04-30 09:11:06 +010017Python Version Compatibility
18++++++++++++++++++++++++++++
Robert Collins18c9bbd2015-07-10 14:00:11 +120019
Chris Withersb793c6a2019-04-30 09:11:06 +010020* Version 1.0.1 is the last version compatible with Python < 2.6.
Michael Foord1e68bec2012-03-03 22:24:30 +000021
Chris Withersb793c6a2019-04-30 09:11:06 +010022* Version 1.3.0 is the last version compatible with Python 3.2.
Michael Foord2df66112012-10-07 18:33:12 +010023
Chris Withersb793c6a2019-04-30 09:11:06 +010024* Version 2.0.0 is the last version compatible with Python 2.6.
Michael Foord1e68bec2012-03-03 22:24:30 +000025
Chris Withers0459be22019-05-02 00:17:02 +010026* Version 2.0.0 is the last version offering official Jython support.
27
Michael Foord1e68bec2012-03-03 22:24:30 +000028.. index:: installing
Robert Collins18c9bbd2015-07-10 14:00:11 +120029.. _installing:
Michael Foord1e68bec2012-03-03 22:24:30 +000030
31Installing
Robert Collins18c9bbd2015-07-10 14:00:11 +120032++++++++++
Michael Foord1e68bec2012-03-03 22:24:30 +000033
Michael Foord1e68bec2012-03-03 22:24:30 +000034.. index:: repository
Robert Collins18c9bbd2015-07-10 14:00:11 +120035.. index:: git
Michael Foord1e68bec2012-03-03 22:24:30 +000036
Hugob67fe8a2017-10-28 16:01:45 +030037You can checkout the latest development version from GitHub
Michael Foord1e68bec2012-03-03 22:24:30 +000038repository with the following command:
39
Chris Withers8a5e0c32019-04-27 14:29:03 +010040 ``git clone https://github.com/testing-cabal/mock.git``
Michael Foord1e68bec2012-03-03 22:24:30 +000041
42
43.. index:: pip
Michael Foord1e68bec2012-03-03 22:24:30 +000044
Robert Collins18c9bbd2015-07-10 14:00:11 +120045You can install mock with pip:
Michael Foord1e68bec2012-03-03 22:24:30 +000046
Michael Foord1e68bec2012-03-03 22:24:30 +000047 | ``pip install -U mock``
48
Robert Collins18c9bbd2015-07-10 14:00:11 +120049.. index:: bug reports
Michael Foord1e68bec2012-03-03 22:24:30 +000050
Robert Collins18c9bbd2015-07-10 14:00:11 +120051Bug Reports
52+++++++++++
Michael Foord1e68bec2012-03-03 22:24:30 +000053
Robert Collins18c9bbd2015-07-10 14:00:11 +120054Issues with the backport process, such as compatibility with a particular
55Python, should be reported to the `bug tracker
56<https://github.com/testing-cabal/mock/issues>`_. Feature requests and issues
57with Mock functionality should be reported to the `Python bug tracker
58<https://bugs.python.org>`_.
Michael Foord1e68bec2012-03-03 22:24:30 +000059
Robert Collins18c9bbd2015-07-10 14:00:11 +120060.. index:: python changes
Michael Foord1e68bec2012-03-03 22:24:30 +000061
Chris Withers66381c02019-05-02 13:24:39 +010062Changelog
63+++++++++
Michael Foord1e68bec2012-03-03 22:24:30 +000064
Chris Withersb793c6a2019-04-30 09:11:06 +010065See the :doc:`change log <changelog>`.
Hugob67fe8a2017-10-28 16:01:45 +030066
Robert Collins18c9bbd2015-07-10 14:00:11 +120067.. index:: maintainer notes
Michael Foord1e68bec2012-03-03 22:24:30 +000068
Robert Collins18c9bbd2015-07-10 14:00:11 +120069Maintainer Notes
70++++++++++++++++
Michael Foord1e68bec2012-03-03 22:24:30 +000071
Robert Collins18c9bbd2015-07-10 14:00:11 +120072Development
Jon Dufresne0f7f20f2018-09-16 18:04:59 -070073-----------
Michael Foord1e68bec2012-03-03 22:24:30 +000074
Robert Collins18c9bbd2015-07-10 14:00:11 +120075Checkout from git (see :ref:`installing`) and submit pull requests.
Michael Foord1e68bec2012-03-03 22:24:30 +000076
Robert Collins18c9bbd2015-07-10 14:00:11 +120077Committers can just push as desired: since all semantic development takes
78place in cPython, the backport process is as lightweight as we can make it.
Michael Foord1e68bec2012-03-03 22:24:30 +000079
Hugo59130a42018-05-08 08:23:53 +030080mock is CI tested using Travis-CI on Python versions 2.7, 3.4,
Chris Withers66381c02019-05-02 13:24:39 +0100813.5, 3.6, pypy, pypy3.
82
83If you end up fixing anything backport-specific, please add an entry
84to the top of ``CHANGELOG.rst`` so it shows up in the next release
85notes.
Michael Foord1e68bec2012-03-03 22:24:30 +000086
Robert Collins18c9bbd2015-07-10 14:00:11 +120087Releasing
Jon Dufresne0f7f20f2018-09-16 18:04:59 -070088---------
Michael Foord1e68bec2012-03-03 22:24:30 +000089
Robert Collinse795a4a2015-07-10 14:32:36 +120090NB: please use semver. Bump the major component on API breaks, minor on all
91non-bugfix changes, patch on bugfix only changes.
92
Chris Withersa9c087d2019-05-02 08:17:51 +0100931. Run ``release.py [major|minor|bugfix]`` which will roll out new
94 NEWS items, bump the version number and create a commit for the release.
Michael Foord1e68bec2012-03-03 22:24:30 +000095
Chris Withersa9c087d2019-05-02 08:17:51 +0100962. Review that commit, feel free to amend it if you want to note anything
97 manually in ``CHANGELOG.rst``.
98
993. Push to the ``master`` branch on
100 https://github.com/testing-cabal/mock.git and the Circle CI
101 automation will take care of pushing releases to PyPI and
102 creating a tag.
Robert Collins18c9bbd2015-07-10 14:00:11 +1200103
104Backporting rules
Jon Dufresne0f7f20f2018-09-16 18:04:59 -0700105-----------------
Robert Collins18c9bbd2015-07-10 14:00:11 +1200106
Chris Withers8a5e0c32019-04-27 14:29:03 +0100107- ``isinstance`` checks in cPython to ``type`` need to check ``ClassTypes``.
108 Code calling ``obj.isidentifier`` needs to change to ``_isidentifier(obj)``.
Robert Collins18c9bbd2015-07-10 14:00:11 +1200109
Chris Witherse684d672019-04-28 20:48:13 +0100110- f-strings need to be rewritten using some other string substitution.
111
Chris Withersd6563802019-04-28 22:38:05 +0100112- ``assertRaisesRegex`` needs to be ``assertRaisesRegexp`` for Python 2.
113
Chris Withersa2e00f42019-04-29 08:17:45 +0100114- If test code won't compile on a particular version of Python, move it to
115 a matching ``_py{version}.py`` file. If ``{version}`` isn't 3, adjust
116 ``conftest.py``.
117
Chris Withersd52cb782019-05-02 07:54:29 +0100118- If code such as this causes coverage checking to drop below 100%:
119
120 .. code-block:: python
121
122 def will_never_be_called():
123 pass
124
125 It should be adjusted to the following pattern, preferably upstream,
126 so that the ``.coveragerc`` in this repo knows to ignore it:
127
128 .. code-block:: python
129
130 def will_never_be_called(): pass
131
Robert Collins18c9bbd2015-07-10 14:00:11 +1200132Backporting process
Jon Dufresne0f7f20f2018-09-16 18:04:59 -0700133-------------------
Robert Collins18c9bbd2015-07-10 14:00:11 +1200134
Chris Withers8a5e0c32019-04-27 14:29:03 +01001351. Clone cpython and mock into the same directory, eg:
Robert Collins18c9bbd2015-07-10 14:00:11 +1200136
Chris Withers8a5e0c32019-04-27 14:29:03 +0100137 .. code-block:: bash
Robert Collins18c9bbd2015-07-10 14:00:11 +1200138
Chris Withers8a5e0c32019-04-27 14:29:03 +0100139 mkdir vcs
140 cd vcs
141 git clone https://github.com/python/cpython.git
142 git clone https://github.com/testing-cabal/mock.git
Robert Collins18c9bbd2015-07-10 14:00:11 +1200143
Chris Withers8a5e0c32019-04-27 14:29:03 +0100144 Make sure they both on master and up to date!
Robert Collins18c9bbd2015-07-10 14:00:11 +1200145
Chris Withers8a5e0c32019-04-27 14:29:03 +01001462. Create a branch in your ``mock`` clone and switch to it.
Robert Collins18c9bbd2015-07-10 14:00:11 +1200147
Chris Withers8a5e0c32019-04-27 14:29:03 +01001483. Make sure you build a suitable virtualenv for Mock development
149 and activate it. For backporting, this should use Python 3.7+.
Robert Collins18c9bbd2015-07-10 14:00:11 +1200150
Chris Withers8a5e0c32019-04-27 14:29:03 +01001514. Run ``backport.py``:
Robert Collins18c9bbd2015-07-10 14:00:11 +1200152
Chris Withers8a5e0c32019-04-27 14:29:03 +0100153 .. code-block:: bash
154
155 cd vcs/mock
156 python backport.py
157
158 This will find the next cpython patch that needs to be applied, munge it
159 and attempt to apply it with ``git am``.
160
161 If it succeeds, run the tests and/or push your branch up to a fork and
162 do a pull request into the master branch of the main repo to kick off
163 the continuous integration tests.
164
165 If it fails, you'll have to manually work with what ``git status`` shows
166 to get the patch committed.
167
Chris Withersa3365182019-04-27 17:35:49 +0100168 If it turns out that there's nothing that should be applied from the failed commit,
Chris Withersa137eb02019-04-28 22:38:16 +0100169 run ``python backport.py --skip-current``, maybe with ``--skip-reason``.
Chris Withersa3365182019-04-27 17:35:49 +0100170
Chris Withers8a5e0c32019-04-27 14:29:03 +0100171 If you have to make changes, please do a ``git commit --amend`` and add notes
172 about what needed doing below the ``Signed-off-by`` block.
173
Chris Withersb0b839f2019-04-27 14:48:34 +0100174 If you have to make changes because tests fail with an applied patch, please
175 make those changes in a followup commit and take note of the "Backporting rules"
176 above.
Chris Withers8a5e0c32019-04-27 14:29:03 +0100177
1785. Rinse and repeat until ``backport.py`` reports no more patches need applying.
Chris Withers871b5262019-04-27 15:04:13 +0100179
1806. If ``backport.py`` has updated ``lastsync.txt``, now would be a good time
181 to commit that change.