blob: bbcb74d385dcb76b40d669d1eefd721f31c6c9e9 [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
26.. index:: installing
Robert Collins18c9bbd2015-07-10 14:00:11 +120027.. _installing:
Michael Foord1e68bec2012-03-03 22:24:30 +000028
29Installing
Robert Collins18c9bbd2015-07-10 14:00:11 +120030++++++++++
Michael Foord1e68bec2012-03-03 22:24:30 +000031
Michael Foord1e68bec2012-03-03 22:24:30 +000032.. index:: repository
Robert Collins18c9bbd2015-07-10 14:00:11 +120033.. index:: git
Michael Foord1e68bec2012-03-03 22:24:30 +000034
Hugob67fe8a2017-10-28 16:01:45 +030035You can checkout the latest development version from GitHub
Michael Foord1e68bec2012-03-03 22:24:30 +000036repository with the following command:
37
Chris Withers8a5e0c32019-04-27 14:29:03 +010038 ``git clone https://github.com/testing-cabal/mock.git``
Michael Foord1e68bec2012-03-03 22:24:30 +000039
40
41.. index:: pip
Michael Foord1e68bec2012-03-03 22:24:30 +000042
Robert Collins18c9bbd2015-07-10 14:00:11 +120043You can install mock with pip:
Michael Foord1e68bec2012-03-03 22:24:30 +000044
Michael Foord1e68bec2012-03-03 22:24:30 +000045 | ``pip install -U mock``
46
Robert Collins18c9bbd2015-07-10 14:00:11 +120047.. index:: bug reports
Michael Foord1e68bec2012-03-03 22:24:30 +000048
Robert Collins18c9bbd2015-07-10 14:00:11 +120049Bug Reports
50+++++++++++
Michael Foord1e68bec2012-03-03 22:24:30 +000051
Robert Collins18c9bbd2015-07-10 14:00:11 +120052Issues with the backport process, such as compatibility with a particular
53Python, should be reported to the `bug tracker
54<https://github.com/testing-cabal/mock/issues>`_. Feature requests and issues
55with Mock functionality should be reported to the `Python bug tracker
56<https://bugs.python.org>`_.
Michael Foord1e68bec2012-03-03 22:24:30 +000057
Robert Collins18c9bbd2015-07-10 14:00:11 +120058.. index:: python changes
Michael Foord1e68bec2012-03-03 22:24:30 +000059
Robert Collins18c9bbd2015-07-10 14:00:11 +120060Python Changes
61++++++++++++++
Michael Foord1e68bec2012-03-03 22:24:30 +000062
Chris Withersb793c6a2019-04-30 09:11:06 +010063See the :doc:`change log <changelog>`.
Hugob67fe8a2017-10-28 16:01:45 +030064
Robert Collins18c9bbd2015-07-10 14:00:11 +120065.. index:: maintainer notes
Michael Foord1e68bec2012-03-03 22:24:30 +000066
Robert Collins18c9bbd2015-07-10 14:00:11 +120067Maintainer Notes
68++++++++++++++++
Michael Foord1e68bec2012-03-03 22:24:30 +000069
Robert Collins18c9bbd2015-07-10 14:00:11 +120070Development
Jon Dufresne0f7f20f2018-09-16 18:04:59 -070071-----------
Michael Foord1e68bec2012-03-03 22:24:30 +000072
Robert Collins18c9bbd2015-07-10 14:00:11 +120073Checkout from git (see :ref:`installing`) and submit pull requests.
Michael Foord1e68bec2012-03-03 22:24:30 +000074
Robert Collins18c9bbd2015-07-10 14:00:11 +120075Committers can just push as desired: since all semantic development takes
76place in cPython, the backport process is as lightweight as we can make it.
Michael Foord1e68bec2012-03-03 22:24:30 +000077
Hugo59130a42018-05-08 08:23:53 +030078mock is CI tested using Travis-CI on Python versions 2.7, 3.4,
793.5, 3.6, nightly Python 3 builds, pypy, pypy3. Jython support is desired, if
lord6305a0ef02015-09-23 10:47:31 +080080someone could contribute a patch to .travis.yml to support it that would be
Robert Collins18c9bbd2015-07-10 14:00:11 +120081excellent.
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
Robert Collins18c9bbd2015-07-10 14:00:11 +1200891. tag -s, push --tags origin master
902. setup.py sdist bdist_wheel upload -s
Michael Foord1e68bec2012-03-03 22:24:30 +000091
Robert Collins18c9bbd2015-07-10 14:00:11 +120092
93Backporting rules
Jon Dufresne0f7f20f2018-09-16 18:04:59 -070094-----------------
Robert Collins18c9bbd2015-07-10 14:00:11 +120095
Chris Withers8a5e0c32019-04-27 14:29:03 +010096- ``isinstance`` checks in cPython to ``type`` need to check ``ClassTypes``.
97 Code calling ``obj.isidentifier`` needs to change to ``_isidentifier(obj)``.
Robert Collins18c9bbd2015-07-10 14:00:11 +120098
Chris Witherse684d672019-04-28 20:48:13 +010099- f-strings need to be rewritten using some other string substitution.
100
Chris Withersd6563802019-04-28 22:38:05 +0100101- ``assertRaisesRegex`` needs to be ``assertRaisesRegexp`` for Python 2.
102
Chris Withersa2e00f42019-04-29 08:17:45 +0100103- If test code won't compile on a particular version of Python, move it to
104 a matching ``_py{version}.py`` file. If ``{version}`` isn't 3, adjust
105 ``conftest.py``.
106
Robert Collins18c9bbd2015-07-10 14:00:11 +1200107Backporting process
Jon Dufresne0f7f20f2018-09-16 18:04:59 -0700108-------------------
Robert Collins18c9bbd2015-07-10 14:00:11 +1200109
Chris Withers8a5e0c32019-04-27 14:29:03 +01001101. Clone cpython and mock into the same directory, eg:
Robert Collins18c9bbd2015-07-10 14:00:11 +1200111
Chris Withers8a5e0c32019-04-27 14:29:03 +0100112 .. code-block:: bash
Robert Collins18c9bbd2015-07-10 14:00:11 +1200113
Chris Withers8a5e0c32019-04-27 14:29:03 +0100114 mkdir vcs
115 cd vcs
116 git clone https://github.com/python/cpython.git
117 git clone https://github.com/testing-cabal/mock.git
Robert Collins18c9bbd2015-07-10 14:00:11 +1200118
Chris Withers8a5e0c32019-04-27 14:29:03 +0100119 Make sure they both on master and up to date!
Robert Collins18c9bbd2015-07-10 14:00:11 +1200120
Chris Withers8a5e0c32019-04-27 14:29:03 +01001212. Create a branch in your ``mock`` clone and switch to it.
Robert Collins18c9bbd2015-07-10 14:00:11 +1200122
Chris Withers8a5e0c32019-04-27 14:29:03 +01001233. Make sure you build a suitable virtualenv for Mock development
124 and activate it. For backporting, this should use Python 3.7+.
Robert Collins18c9bbd2015-07-10 14:00:11 +1200125
Chris Withers8a5e0c32019-04-27 14:29:03 +01001264. Run ``backport.py``:
Robert Collins18c9bbd2015-07-10 14:00:11 +1200127
Chris Withers8a5e0c32019-04-27 14:29:03 +0100128 .. code-block:: bash
129
130 cd vcs/mock
131 python backport.py
132
133 This will find the next cpython patch that needs to be applied, munge it
134 and attempt to apply it with ``git am``.
135
136 If it succeeds, run the tests and/or push your branch up to a fork and
137 do a pull request into the master branch of the main repo to kick off
138 the continuous integration tests.
139
140 If it fails, you'll have to manually work with what ``git status`` shows
141 to get the patch committed.
142
Chris Withersa3365182019-04-27 17:35:49 +0100143 If it turns out that there's nothing that should be applied from the failed commit,
Chris Withersa137eb02019-04-28 22:38:16 +0100144 run ``python backport.py --skip-current``, maybe with ``--skip-reason``.
Chris Withersa3365182019-04-27 17:35:49 +0100145
Chris Withers8a5e0c32019-04-27 14:29:03 +0100146 If you have to make changes, please do a ``git commit --amend`` and add notes
147 about what needed doing below the ``Signed-off-by`` block.
148
Chris Withersb0b839f2019-04-27 14:48:34 +0100149 If you have to make changes because tests fail with an applied patch, please
150 make those changes in a followup commit and take note of the "Backporting rules"
151 above.
Chris Withers8a5e0c32019-04-27 14:29:03 +0100152
1535. Rinse and repeat until ``backport.py`` reports no more patches need applying.
Chris Withers871b5262019-04-27 15:04:13 +0100154
1556. If ``backport.py`` has updated ``lastsync.txt``, now would be a good time
156 to commit that change.