blob: 68876e8965753fe7ac70648994a0537bbea99e6c [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
Robert Collins18c9bbd2015-07-10 14:00:11 +120062Python Changes
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 Withers0459be22019-05-02 00:17:02 +0100813.5, 3.6, nightly Python 3 builds, pypy, pypy3.
Michael Foord1e68bec2012-03-03 22:24:30 +000082
Robert Collins18c9bbd2015-07-10 14:00:11 +120083Releasing
Jon Dufresne0f7f20f2018-09-16 18:04:59 -070084---------
Michael Foord1e68bec2012-03-03 22:24:30 +000085
Robert Collinse795a4a2015-07-10 14:32:36 +120086NB: please use semver. Bump the major component on API breaks, minor on all
87non-bugfix changes, patch on bugfix only changes.
88
Chris Withersa9c087d2019-05-02 08:17:51 +0100891. Run ``release.py [major|minor|bugfix]`` which will roll out new
90 NEWS items, bump the version number and create a commit for the release.
Michael Foord1e68bec2012-03-03 22:24:30 +000091
Chris Withersa9c087d2019-05-02 08:17:51 +0100922. Review that commit, feel free to amend it if you want to note anything
93 manually in ``CHANGELOG.rst``.
94
953. Push to the ``master`` branch on
96 https://github.com/testing-cabal/mock.git and the Circle CI
97 automation will take care of pushing releases to PyPI and
98 creating a tag.
Robert Collins18c9bbd2015-07-10 14:00:11 +120099
100Backporting rules
Jon Dufresne0f7f20f2018-09-16 18:04:59 -0700101-----------------
Robert Collins18c9bbd2015-07-10 14:00:11 +1200102
Chris Withers8a5e0c32019-04-27 14:29:03 +0100103- ``isinstance`` checks in cPython to ``type`` need to check ``ClassTypes``.
104 Code calling ``obj.isidentifier`` needs to change to ``_isidentifier(obj)``.
Robert Collins18c9bbd2015-07-10 14:00:11 +1200105
Chris Witherse684d672019-04-28 20:48:13 +0100106- f-strings need to be rewritten using some other string substitution.
107
Chris Withersd6563802019-04-28 22:38:05 +0100108- ``assertRaisesRegex`` needs to be ``assertRaisesRegexp`` for Python 2.
109
Chris Withersa2e00f42019-04-29 08:17:45 +0100110- If test code won't compile on a particular version of Python, move it to
111 a matching ``_py{version}.py`` file. If ``{version}`` isn't 3, adjust
112 ``conftest.py``.
113
Chris Withersd52cb782019-05-02 07:54:29 +0100114- If code such as this causes coverage checking to drop below 100%:
115
116 .. code-block:: python
117
118 def will_never_be_called():
119 pass
120
121 It should be adjusted to the following pattern, preferably upstream,
122 so that the ``.coveragerc`` in this repo knows to ignore it:
123
124 .. code-block:: python
125
126 def will_never_be_called(): pass
127
Robert Collins18c9bbd2015-07-10 14:00:11 +1200128Backporting process
Jon Dufresne0f7f20f2018-09-16 18:04:59 -0700129-------------------
Robert Collins18c9bbd2015-07-10 14:00:11 +1200130
Chris Withers8a5e0c32019-04-27 14:29:03 +01001311. Clone cpython and mock into the same directory, eg:
Robert Collins18c9bbd2015-07-10 14:00:11 +1200132
Chris Withers8a5e0c32019-04-27 14:29:03 +0100133 .. code-block:: bash
Robert Collins18c9bbd2015-07-10 14:00:11 +1200134
Chris Withers8a5e0c32019-04-27 14:29:03 +0100135 mkdir vcs
136 cd vcs
137 git clone https://github.com/python/cpython.git
138 git clone https://github.com/testing-cabal/mock.git
Robert Collins18c9bbd2015-07-10 14:00:11 +1200139
Chris Withers8a5e0c32019-04-27 14:29:03 +0100140 Make sure they both on master and up to date!
Robert Collins18c9bbd2015-07-10 14:00:11 +1200141
Chris Withers8a5e0c32019-04-27 14:29:03 +01001422. Create a branch in your ``mock`` clone and switch to it.
Robert Collins18c9bbd2015-07-10 14:00:11 +1200143
Chris Withers8a5e0c32019-04-27 14:29:03 +01001443. Make sure you build a suitable virtualenv for Mock development
145 and activate it. For backporting, this should use Python 3.7+.
Robert Collins18c9bbd2015-07-10 14:00:11 +1200146
Chris Withers8a5e0c32019-04-27 14:29:03 +01001474. Run ``backport.py``:
Robert Collins18c9bbd2015-07-10 14:00:11 +1200148
Chris Withers8a5e0c32019-04-27 14:29:03 +0100149 .. code-block:: bash
150
151 cd vcs/mock
152 python backport.py
153
154 This will find the next cpython patch that needs to be applied, munge it
155 and attempt to apply it with ``git am``.
156
157 If it succeeds, run the tests and/or push your branch up to a fork and
158 do a pull request into the master branch of the main repo to kick off
159 the continuous integration tests.
160
161 If it fails, you'll have to manually work with what ``git status`` shows
162 to get the patch committed.
163
Chris Withersa3365182019-04-27 17:35:49 +0100164 If it turns out that there's nothing that should be applied from the failed commit,
Chris Withersa137eb02019-04-28 22:38:16 +0100165 run ``python backport.py --skip-current``, maybe with ``--skip-reason``.
Chris Withersa3365182019-04-27 17:35:49 +0100166
Chris Withers8a5e0c32019-04-27 14:29:03 +0100167 If you have to make changes, please do a ``git commit --amend`` and add notes
168 about what needed doing below the ``Signed-off-by`` block.
169
Chris Withersb0b839f2019-04-27 14:48:34 +0100170 If you have to make changes because tests fail with an applied patch, please
171 make those changes in a followup commit and take note of the "Backporting rules"
172 above.
Chris Withers8a5e0c32019-04-27 14:29:03 +0100173
1745. Rinse and repeat until ``backport.py`` reports no more patches need applying.
Chris Withers871b5262019-04-27 15:04:13 +0100175
1766. If ``backport.py`` has updated ``lastsync.txt``, now would be a good time
177 to commit that change.