Compare commits
5 commits
d29b628982
...
1f809b8dbb
Author | SHA1 | Date | |
---|---|---|---|
1f809b8dbb | |||
110f3d85ec | |||
a909201310 | |||
8bf36e87d2 | |||
62436189d4 |
19
.github/workflows/test.yml
vendored
19
.github/workflows/test.yml
vendored
|
@ -31,19 +31,16 @@ jobs:
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
python: ["3.7", "3.8", "3.9", "3.10", "3.11"]
|
python: ["3.8", "3.9", "3.10", "3.11", "3.12"]
|
||||||
os: [ubuntu-latest, windows-latest]
|
os: [ubuntu-latest, windows-latest]
|
||||||
|
tox_env: ["py"]
|
||||||
include:
|
include:
|
||||||
- python: "3.7"
|
- python: "3.12"
|
||||||
tox_env: "py37"
|
os: ubuntu-latest
|
||||||
- python: "3.8"
|
tox_env: "norewrite"
|
||||||
tox_env: "py38"
|
- python: "3.12"
|
||||||
- python: "3.9"
|
os: windows-latest
|
||||||
tox_env: "py39"
|
tox_env: "norewrite"
|
||||||
- python: "3.10"
|
|
||||||
tox_env: "py310"
|
|
||||||
- python: "3.11"
|
|
||||||
tox_env: "py311"
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
exclude: '^($|.*\.bin)'
|
exclude: '^($|.*\.bin)'
|
||||||
repos:
|
repos:
|
||||||
- repo: https://github.com/psf/black
|
- repo: https://github.com/psf/black
|
||||||
rev: 23.3.0
|
rev: 23.9.1
|
||||||
hooks:
|
hooks:
|
||||||
- id: black
|
- id: black
|
||||||
args: [--safe, --quiet]
|
args: [--safe, --quiet]
|
||||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||||
rev: v4.4.0
|
rev: v4.5.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: trailing-whitespace
|
- id: trailing-whitespace
|
||||||
- id: end-of-file-fixer
|
- id: end-of-file-fixer
|
||||||
|
@ -19,12 +19,12 @@ repos:
|
||||||
language: python
|
language: python
|
||||||
additional_dependencies: [pygments, restructuredtext_lint]
|
additional_dependencies: [pygments, restructuredtext_lint]
|
||||||
- repo: https://github.com/asottile/reorder-python-imports
|
- repo: https://github.com/asottile/reorder-python-imports
|
||||||
rev: v3.9.0
|
rev: v3.12.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: reorder-python-imports
|
- id: reorder-python-imports
|
||||||
args: ['--application-directories=.:src']
|
args: ['--application-directories=.:src']
|
||||||
- repo: https://github.com/pre-commit/mirrors-mypy
|
- repo: https://github.com/pre-commit/mirrors-mypy
|
||||||
rev: v1.3.0 # NOTE: keep this in sync with tox.ini
|
rev: v1.6.0 # NOTE: keep this in sync with tox.ini
|
||||||
hooks:
|
hooks:
|
||||||
- id: mypy
|
- id: mypy
|
||||||
files: ^(src|tests)
|
files: ^(src|tests)
|
||||||
|
|
15
.readthedocs.yml
Normal file
15
.readthedocs.yml
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
version: 2
|
||||||
|
|
||||||
|
build:
|
||||||
|
os: ubuntu-22.04
|
||||||
|
tools:
|
||||||
|
python: "3.11"
|
||||||
|
|
||||||
|
sphinx:
|
||||||
|
configuration: docs/conf.py
|
||||||
|
fail_on_warning: true
|
||||||
|
|
||||||
|
python:
|
||||||
|
install:
|
||||||
|
- requirements: docs/requirements.txt
|
||||||
|
- path: .
|
|
@ -1,9 +1,30 @@
|
||||||
Releases
|
Releases
|
||||||
========
|
========
|
||||||
|
|
||||||
|
3.12.0 (2023-10-19)
|
||||||
|
-------------------
|
||||||
|
|
||||||
|
* Added support for Python 3.12.
|
||||||
|
* Dropped support for EOL Python 3.7.
|
||||||
|
* ``mocker.resetall()`` now also resets mocks created by ``mocker.create_autospec`` (`#390`_).
|
||||||
|
|
||||||
|
.. _#390: https://github.com/pytest-dev/pytest-mock/pull/390
|
||||||
|
|
||||||
3.11.1 (2023-06-15)
|
3.11.1 (2023-06-15)
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
|
(This release source code is identical to ``3.11.0`` except a small internal fix to deployment/CI)
|
||||||
|
|
||||||
|
* Fixed introspection for failed ``assert_has_calls`` (`#365`_).
|
||||||
|
|
||||||
|
* Updated type annotations for ``mocker.patch`` and ``mocker.spy`` (`#364`_).
|
||||||
|
|
||||||
|
.. _#365: https://github.com/pytest-dev/pytest-mock/pull/365
|
||||||
|
.. _#364: https://github.com/pytest-dev/pytest-mock/pull/364
|
||||||
|
|
||||||
|
3.11.0 (2023-06-15)
|
||||||
|
-------------------
|
||||||
|
|
||||||
* Fixed introspection for failed ``assert_has_calls`` (`#365`_).
|
* Fixed introspection for failed ``assert_has_calls`` (`#365`_).
|
||||||
|
|
||||||
* Updated type annotations for ``mocker.patch`` and ``mocker.spy`` (`#364`_).
|
* Updated type annotations for ``mocker.patch`` and ``mocker.spy`` (`#364`_).
|
||||||
|
|
12
PKG-INFO
12
PKG-INFO
|
@ -1,6 +1,6 @@
|
||||||
Metadata-Version: 2.1
|
Metadata-Version: 2.1
|
||||||
Name: pytest-mock
|
Name: pytest-mock
|
||||||
Version: 3.11.1
|
Version: 3.12.0
|
||||||
Summary: Thin-wrapper around the mock package for easier use with pytest
|
Summary: Thin-wrapper around the mock package for easier use with pytest
|
||||||
Home-page: https://github.com/pytest-dev/pytest-mock/
|
Home-page: https://github.com/pytest-dev/pytest-mock/
|
||||||
Author: Bruno Oliveira
|
Author: Bruno Oliveira
|
||||||
|
@ -18,17 +18,21 @@ Classifier: Intended Audience :: Developers
|
||||||
Classifier: License :: OSI Approved :: MIT License
|
Classifier: License :: OSI Approved :: MIT License
|
||||||
Classifier: Operating System :: OS Independent
|
Classifier: Operating System :: OS Independent
|
||||||
Classifier: Programming Language :: Python :: 3
|
Classifier: Programming Language :: Python :: 3
|
||||||
Classifier: Programming Language :: Python :: 3.7
|
|
||||||
Classifier: Programming Language :: Python :: 3.8
|
Classifier: Programming Language :: Python :: 3.8
|
||||||
Classifier: Programming Language :: Python :: 3.9
|
Classifier: Programming Language :: Python :: 3.9
|
||||||
Classifier: Programming Language :: Python :: 3.10
|
Classifier: Programming Language :: Python :: 3.10
|
||||||
Classifier: Programming Language :: Python :: 3.11
|
Classifier: Programming Language :: Python :: 3.11
|
||||||
|
Classifier: Programming Language :: Python :: 3.12
|
||||||
Classifier: Programming Language :: Python :: 3 :: Only
|
Classifier: Programming Language :: Python :: 3 :: Only
|
||||||
Classifier: Topic :: Software Development :: Testing
|
Classifier: Topic :: Software Development :: Testing
|
||||||
Requires-Python: >=3.7
|
Requires-Python: >=3.8
|
||||||
Description-Content-Type: text/x-rst
|
Description-Content-Type: text/x-rst
|
||||||
Provides-Extra: dev
|
|
||||||
License-File: LICENSE
|
License-File: LICENSE
|
||||||
|
Requires-Dist: pytest>=5.0
|
||||||
|
Provides-Extra: dev
|
||||||
|
Requires-Dist: pre-commit; extra == "dev"
|
||||||
|
Requires-Dist: tox; extra == "dev"
|
||||||
|
Requires-Dist: pytest-asyncio; extra == "dev"
|
||||||
|
|
||||||
===========
|
===========
|
||||||
pytest-mock
|
pytest-mock
|
||||||
|
|
9
debian/changelog
vendored
9
debian/changelog
vendored
|
@ -1,3 +1,12 @@
|
||||||
|
pytest-mock (3.12.0-1) unstable; urgency=medium
|
||||||
|
|
||||||
|
* Team upload.
|
||||||
|
* New upstream version 3.12.0
|
||||||
|
* Drop Sphinx theme patch; furo is available
|
||||||
|
* Explicitly clean egg info
|
||||||
|
|
||||||
|
-- Timo Röhling <roehling@debian.org> Mon, 13 Nov 2023 00:46:56 +0100
|
||||||
|
|
||||||
pytest-mock (3.11.1-2) unstable; urgency=medium
|
pytest-mock (3.11.1-2) unstable; urgency=medium
|
||||||
|
|
||||||
* Team upload.
|
* Team upload.
|
||||||
|
|
1
debian/clean
vendored
Normal file
1
debian/clean
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
src/*.egg-info/
|
2
debian/control
vendored
2
debian/control
vendored
|
@ -6,6 +6,7 @@ Priority: optional
|
||||||
Build-Depends: debhelper-compat (= 13),
|
Build-Depends: debhelper-compat (= 13),
|
||||||
dh-python,
|
dh-python,
|
||||||
dh-sequence-python3,
|
dh-sequence-python3,
|
||||||
|
furo <!nodoc>,
|
||||||
python3-all,
|
python3-all,
|
||||||
python3-mock,
|
python3-mock,
|
||||||
python3-pytest (>= 7.1.2),
|
python3-pytest (>= 7.1.2),
|
||||||
|
@ -13,7 +14,6 @@ Build-Depends: debhelper-compat (= 13),
|
||||||
python3-setuptools,
|
python3-setuptools,
|
||||||
python3-setuptools-scm,
|
python3-setuptools-scm,
|
||||||
python3-sphinx-copybutton <!nodoc>,
|
python3-sphinx-copybutton <!nodoc>,
|
||||||
python3-sphinx-rtd-theme <!nodoc>,
|
|
||||||
sphinx <!nodoc>
|
sphinx <!nodoc>
|
||||||
Standards-Version: 4.6.2
|
Standards-Version: 4.6.2
|
||||||
Vcs-Browser: https://salsa.debian.org/python-team/packages/pytest-mock
|
Vcs-Browser: https://salsa.debian.org/python-team/packages/pytest-mock
|
||||||
|
|
18
debian/patches/change_sphinx_theme.patch
vendored
18
debian/patches/change_sphinx_theme.patch
vendored
|
@ -1,18 +0,0 @@
|
||||||
Description: Use already packaged theme for documentation
|
|
||||||
Upstream uses the furo theme, which has not been packaged for Debian.
|
|
||||||
We switch to the common RTD theme instead.
|
|
||||||
Forwarded: not-needed
|
|
||||||
Author: Julian Gilbey <jdg@debian.org>
|
|
||||||
Last-Update: 2022-07-15
|
|
||||||
|
|
||||||
--- a/docs/conf.py
|
|
||||||
+++ b/docs/conf.py
|
|
||||||
@@ -42,7 +42,7 @@
|
|
||||||
# The theme to use for HTML and HTML Help pages. See the documentation for
|
|
||||||
# a list of builtin themes.
|
|
||||||
#
|
|
||||||
-html_theme = "furo"
|
|
||||||
+html_theme = "sphinx_rtd_theme"
|
|
||||||
|
|
||||||
# Add any paths that contain custom static files (such as style sheets) here,
|
|
||||||
# relative to this directory. They are copied after the builtin static files,
|
|
1
debian/patches/series
vendored
1
debian/patches/series
vendored
|
@ -1 +0,0 @@
|
||||||
change_sphinx_theme.patch
|
|
|
@ -100,23 +100,3 @@ to improve the flow of the test:
|
||||||
# ...
|
# ...
|
||||||
|
|
||||||
But this is arguably a little more complex than using ``pytest-mock``.
|
But this is arguably a little more complex than using ``pytest-mock``.
|
||||||
|
|
||||||
Usage as context manager
|
|
||||||
------------------------
|
|
||||||
|
|
||||||
Although mocker's API is intentionally the same as ``mock.patch``'s, its use
|
|
||||||
as context manager and function decorator is **not** supported through the
|
|
||||||
fixture:
|
|
||||||
|
|
||||||
.. code-block:: python
|
|
||||||
|
|
||||||
def test_context_manager(mocker):
|
|
||||||
a = A()
|
|
||||||
with mocker.patch.object(a, 'doIt', return_value=True, autospec=True): # DO NOT DO THIS
|
|
||||||
assert a.doIt() == True
|
|
||||||
|
|
||||||
The purpose of this plugin is to make the use of context managers and
|
|
||||||
function decorators for mocking unnecessary, so it will emit a warning when used as such.
|
|
||||||
|
|
||||||
If you really intend to mock a context manager, ``mocker.patch.context_manager`` exists
|
|
||||||
which won't issue the above warning.
|
|
||||||
|
|
|
@ -136,3 +136,33 @@ It may receive an optional name that is shown in its ``repr``, useful for debugg
|
||||||
.. seealso::
|
.. seealso::
|
||||||
|
|
||||||
``async_stub`` method, which actually the same as ``stub`` but makes async stub.
|
``async_stub`` method, which actually the same as ``stub`` but makes async stub.
|
||||||
|
|
||||||
|
|
||||||
|
Usage as context manager
|
||||||
|
------------------------
|
||||||
|
|
||||||
|
Although mocker's API is intentionally the same as ``mock.patch``'s, its use
|
||||||
|
as context manager and function decorator is **not** supported through the
|
||||||
|
fixture:
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
def test_context_manager(mocker):
|
||||||
|
a = A()
|
||||||
|
with mocker.patch.object(a, 'doIt', return_value=True, autospec=True): # DO NOT DO THIS
|
||||||
|
assert a.doIt() == True
|
||||||
|
|
||||||
|
The purpose of this plugin is to make the use of context managers and
|
||||||
|
function decorators for mocking unnecessary, so it will emit a warning when used as such.
|
||||||
|
|
||||||
|
If you really intend to mock a context manager, ``mocker.patch.context_manager`` exists
|
||||||
|
which won't issue the above warning.
|
||||||
|
|
||||||
|
Where to patch
|
||||||
|
--------------
|
||||||
|
|
||||||
|
A common issue where mocking appears not to be working is patching in the wrong place.
|
||||||
|
|
||||||
|
See this `section in the unittest docs <https://docs.python.org/3/library/unittest.mock.html#where-to-patch>`__ which provides a comprehensive explanation.
|
||||||
|
|
||||||
|
Also see this excellent blog post: `Why your mock doesn't work <https://nedbatchelder.com/blog/201908/why_your_mock_doesnt_work.html>`__.
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
"""
|
"""
|
||||||
Generates the release notes for the latest release, in Markdown.
|
Generates the release notes for the latest release, in Markdown.
|
||||||
|
|
||||||
Convert CHANGELOG.rst to Markdown, and extracts just the latest release.
|
1. Extracts the latest release from the CHANGELOG.rst file.
|
||||||
|
2. Converts it to Markdown using pypandoc.
|
||||||
Writes to ``scripts/latest-release-notes.md``, which can be
|
3. Writes to ``scripts/latest-release-notes.md``, which can be
|
||||||
used with https://github.com/softprops/action-gh-release.
|
used with https://github.com/softprops/action-gh-release.
|
||||||
"""
|
"""
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
@ -12,25 +12,36 @@ import pypandoc
|
||||||
|
|
||||||
this_dir = Path(__file__).parent
|
this_dir = Path(__file__).parent
|
||||||
rst_text = (this_dir.parent / "CHANGELOG.rst").read_text(encoding="UTF-8")
|
rst_text = (this_dir.parent / "CHANGELOG.rst").read_text(encoding="UTF-8")
|
||||||
md_text = pypandoc.convert_text(
|
|
||||||
rst_text, "md", format="rst", extra_args=["--wrap=preserve"]
|
|
||||||
)
|
|
||||||
|
|
||||||
output_lines = []
|
output_lines = []
|
||||||
first_heading_found = False
|
capture = False
|
||||||
for line in md_text.splitlines():
|
for line in rst_text.splitlines():
|
||||||
if line.startswith("# "):
|
# Only start capturing after the latest release section.
|
||||||
# Skip the first section (normally # Releases).
|
if line.startswith("-------"):
|
||||||
pass
|
capture = not capture
|
||||||
elif line.startswith("## "):
|
if not capture:
|
||||||
# First second-level section, note it and skip the text,
|
# We only need to capture the latest release, so stop.
|
||||||
# as we are only interested in the individual release items.
|
|
||||||
if first_heading_found:
|
|
||||||
break
|
break
|
||||||
first_heading_found = True
|
continue
|
||||||
else:
|
|
||||||
|
if capture:
|
||||||
output_lines.append(line)
|
output_lines.append(line)
|
||||||
|
|
||||||
|
# Drop last line, as it contains the previous release section title.
|
||||||
|
del output_lines[-1]
|
||||||
|
|
||||||
|
trimmed_rst = "\n".join(output_lines).strip()
|
||||||
|
print(">>Trimmed RST follows:")
|
||||||
|
print(trimmed_rst)
|
||||||
|
print(">>Trimmed RST ends")
|
||||||
|
|
||||||
|
md_text = pypandoc.convert_text(
|
||||||
|
trimmed_rst, "md", format="rst", extra_args=["--wrap=preserve"]
|
||||||
|
)
|
||||||
|
print(">>Converted Markdown follows:")
|
||||||
|
print(md_text)
|
||||||
|
print(">>Converted Markdown ends")
|
||||||
|
|
||||||
output_fn = this_dir / "latest-release-notes.md"
|
output_fn = this_dir / "latest-release-notes.md"
|
||||||
output_fn.write_text("\n".join(output_lines), encoding="UTF-8")
|
output_fn.write_text(md_text, encoding="UTF-8")
|
||||||
print(output_fn, "generated.")
|
print(output_fn, "generated.")
|
||||||
|
|
4
setup.py
4
setup.py
|
@ -10,7 +10,7 @@ setup(
|
||||||
package_data={
|
package_data={
|
||||||
"pytest_mock": ["py.typed"],
|
"pytest_mock": ["py.typed"],
|
||||||
},
|
},
|
||||||
python_requires=">=3.7",
|
python_requires=">=3.8",
|
||||||
install_requires=["pytest>=5.0"],
|
install_requires=["pytest>=5.0"],
|
||||||
use_scm_version={"write_to": "src/pytest_mock/_version.py"},
|
use_scm_version={"write_to": "src/pytest_mock/_version.py"},
|
||||||
setup_requires=["setuptools_scm"],
|
setup_requires=["setuptools_scm"],
|
||||||
|
@ -30,11 +30,11 @@ setup(
|
||||||
"License :: OSI Approved :: MIT License",
|
"License :: OSI Approved :: MIT License",
|
||||||
"Operating System :: OS Independent",
|
"Operating System :: OS Independent",
|
||||||
"Programming Language :: Python :: 3",
|
"Programming Language :: Python :: 3",
|
||||||
"Programming Language :: Python :: 3.7",
|
|
||||||
"Programming Language :: Python :: 3.8",
|
"Programming Language :: Python :: 3.8",
|
||||||
"Programming Language :: Python :: 3.9",
|
"Programming Language :: Python :: 3.9",
|
||||||
"Programming Language :: Python :: 3.10",
|
"Programming Language :: Python :: 3.10",
|
||||||
"Programming Language :: Python :: 3.11",
|
"Programming Language :: Python :: 3.11",
|
||||||
|
"Programming Language :: Python :: 3.12",
|
||||||
"Programming Language :: Python :: 3 :: Only",
|
"Programming Language :: Python :: 3 :: Only",
|
||||||
"Topic :: Software Development :: Testing",
|
"Topic :: Software Development :: Testing",
|
||||||
],
|
],
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
Metadata-Version: 2.1
|
Metadata-Version: 2.1
|
||||||
Name: pytest-mock
|
Name: pytest-mock
|
||||||
Version: 3.11.1
|
Version: 3.12.0
|
||||||
Summary: Thin-wrapper around the mock package for easier use with pytest
|
Summary: Thin-wrapper around the mock package for easier use with pytest
|
||||||
Home-page: https://github.com/pytest-dev/pytest-mock/
|
Home-page: https://github.com/pytest-dev/pytest-mock/
|
||||||
Author: Bruno Oliveira
|
Author: Bruno Oliveira
|
||||||
|
@ -18,17 +18,21 @@ Classifier: Intended Audience :: Developers
|
||||||
Classifier: License :: OSI Approved :: MIT License
|
Classifier: License :: OSI Approved :: MIT License
|
||||||
Classifier: Operating System :: OS Independent
|
Classifier: Operating System :: OS Independent
|
||||||
Classifier: Programming Language :: Python :: 3
|
Classifier: Programming Language :: Python :: 3
|
||||||
Classifier: Programming Language :: Python :: 3.7
|
|
||||||
Classifier: Programming Language :: Python :: 3.8
|
Classifier: Programming Language :: Python :: 3.8
|
||||||
Classifier: Programming Language :: Python :: 3.9
|
Classifier: Programming Language :: Python :: 3.9
|
||||||
Classifier: Programming Language :: Python :: 3.10
|
Classifier: Programming Language :: Python :: 3.10
|
||||||
Classifier: Programming Language :: Python :: 3.11
|
Classifier: Programming Language :: Python :: 3.11
|
||||||
|
Classifier: Programming Language :: Python :: 3.12
|
||||||
Classifier: Programming Language :: Python :: 3 :: Only
|
Classifier: Programming Language :: Python :: 3 :: Only
|
||||||
Classifier: Topic :: Software Development :: Testing
|
Classifier: Topic :: Software Development :: Testing
|
||||||
Requires-Python: >=3.7
|
Requires-Python: >=3.8
|
||||||
Description-Content-Type: text/x-rst
|
Description-Content-Type: text/x-rst
|
||||||
Provides-Extra: dev
|
|
||||||
License-File: LICENSE
|
License-File: LICENSE
|
||||||
|
Requires-Dist: pytest>=5.0
|
||||||
|
Provides-Extra: dev
|
||||||
|
Requires-Dist: pre-commit; extra == "dev"
|
||||||
|
Requires-Dist: tox; extra == "dev"
|
||||||
|
Requires-Dist: pytest-asyncio; extra == "dev"
|
||||||
|
|
||||||
===========
|
===========
|
||||||
pytest-mock
|
pytest-mock
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
.gitignore
|
.gitignore
|
||||||
.pre-commit-config.yaml
|
.pre-commit-config.yaml
|
||||||
|
.readthedocs.yml
|
||||||
CHANGELOG.rst
|
CHANGELOG.rst
|
||||||
LICENSE
|
LICENSE
|
||||||
README.rst
|
README.rst
|
||||||
|
|
|
@ -1,4 +1,16 @@
|
||||||
# file generated by setuptools_scm
|
# file generated by setuptools_scm
|
||||||
# don't change, don't track in version control
|
# don't change, don't track in version control
|
||||||
__version__ = version = '3.11.1'
|
TYPE_CHECKING = False
|
||||||
__version_tuple__ = version_tuple = (3, 11, 1)
|
if TYPE_CHECKING:
|
||||||
|
from typing import Tuple, Union
|
||||||
|
VERSION_TUPLE = Tuple[Union[int, str], ...]
|
||||||
|
else:
|
||||||
|
VERSION_TUPLE = object
|
||||||
|
|
||||||
|
version: str
|
||||||
|
__version__: str
|
||||||
|
__version_tuple__: VERSION_TUPLE
|
||||||
|
version_tuple: VERSION_TUPLE
|
||||||
|
|
||||||
|
__version__ = version = '3.12.0'
|
||||||
|
__version_tuple__ = version_tuple = (3, 12, 0)
|
||||||
|
|
|
@ -66,12 +66,20 @@ class MockerFixture:
|
||||||
self.call = mock_module.call
|
self.call = mock_module.call
|
||||||
self.ANY = mock_module.ANY
|
self.ANY = mock_module.ANY
|
||||||
self.DEFAULT = mock_module.DEFAULT
|
self.DEFAULT = mock_module.DEFAULT
|
||||||
self.create_autospec = mock_module.create_autospec
|
|
||||||
self.sentinel = mock_module.sentinel
|
self.sentinel = mock_module.sentinel
|
||||||
self.mock_open = mock_module.mock_open
|
self.mock_open = mock_module.mock_open
|
||||||
if hasattr(mock_module, "seal"):
|
if hasattr(mock_module, "seal"):
|
||||||
self.seal = mock_module.seal
|
self.seal = mock_module.seal
|
||||||
|
|
||||||
|
def create_autospec(
|
||||||
|
self, spec: Any, spec_set: bool = False, instance: bool = False, **kwargs: Any
|
||||||
|
) -> MockType:
|
||||||
|
m: MockType = self.mock_module.create_autospec(
|
||||||
|
spec, spec_set, instance, **kwargs
|
||||||
|
)
|
||||||
|
self._patches_and_mocks.append((None, m))
|
||||||
|
return m
|
||||||
|
|
||||||
def resetall(
|
def resetall(
|
||||||
self, *, return_value: bool = False, side_effect: bool = False
|
self, *, return_value: bool = False, side_effect: bool = False
|
||||||
) -> None:
|
) -> None:
|
||||||
|
@ -102,7 +110,8 @@ class MockerFixture:
|
||||||
times.
|
times.
|
||||||
"""
|
"""
|
||||||
for p, m in reversed(self._patches_and_mocks):
|
for p, m in reversed(self._patches_and_mocks):
|
||||||
p.stop()
|
if p is not None:
|
||||||
|
p.stop()
|
||||||
self._patches_and_mocks.clear()
|
self._patches_and_mocks.clear()
|
||||||
|
|
||||||
def stop(self, mock: unittest.mock.MagicMock) -> None:
|
def stop(self, mock: unittest.mock.MagicMock) -> None:
|
||||||
|
|
|
@ -60,6 +60,15 @@ class UnixFS:
|
||||||
return os.listdir(path)
|
return os.listdir(path)
|
||||||
|
|
||||||
|
|
||||||
|
class TestObject:
|
||||||
|
"""
|
||||||
|
Class that is used for testing create_autospec with child mocks
|
||||||
|
"""
|
||||||
|
|
||||||
|
def run(self) -> str:
|
||||||
|
return "not mocked"
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def check_unix_fs_mocked(
|
def check_unix_fs_mocked(
|
||||||
tmpdir: Any, mocker: MockerFixture
|
tmpdir: Any, mocker: MockerFixture
|
||||||
|
@ -156,7 +165,6 @@ def test_mock_patch_dict_resetall(mocker: MockerFixture) -> None:
|
||||||
[
|
[
|
||||||
"ANY",
|
"ANY",
|
||||||
"call",
|
"call",
|
||||||
"create_autospec",
|
|
||||||
"MagicMock",
|
"MagicMock",
|
||||||
"Mock",
|
"Mock",
|
||||||
"mock_open",
|
"mock_open",
|
||||||
|
@ -185,23 +193,35 @@ def test_mocker_resetall(mocker: MockerFixture) -> None:
|
||||||
listdir = mocker.patch("os.listdir", return_value="foo")
|
listdir = mocker.patch("os.listdir", return_value="foo")
|
||||||
open = mocker.patch("os.open", side_effect=["bar", "baz"])
|
open = mocker.patch("os.open", side_effect=["bar", "baz"])
|
||||||
|
|
||||||
|
mocked_object = mocker.create_autospec(TestObject)
|
||||||
|
mocked_object.run.return_value = "mocked"
|
||||||
|
|
||||||
assert listdir("/tmp") == "foo"
|
assert listdir("/tmp") == "foo"
|
||||||
assert open("/tmp/foo.txt") == "bar"
|
assert open("/tmp/foo.txt") == "bar"
|
||||||
|
assert mocked_object.run() == "mocked"
|
||||||
listdir.assert_called_once_with("/tmp")
|
listdir.assert_called_once_with("/tmp")
|
||||||
open.assert_called_once_with("/tmp/foo.txt")
|
open.assert_called_once_with("/tmp/foo.txt")
|
||||||
|
mocked_object.run.assert_called_once()
|
||||||
|
|
||||||
mocker.resetall()
|
mocker.resetall()
|
||||||
|
|
||||||
assert not listdir.called
|
assert not listdir.called
|
||||||
assert not open.called
|
assert not open.called
|
||||||
|
assert not mocked_object.called
|
||||||
assert listdir.return_value == "foo"
|
assert listdir.return_value == "foo"
|
||||||
assert list(open.side_effect) == ["baz"]
|
assert list(open.side_effect) == ["baz"]
|
||||||
|
assert mocked_object.run.return_value == "mocked"
|
||||||
|
|
||||||
mocker.resetall(return_value=True, side_effect=True)
|
mocker.resetall(return_value=True, side_effect=True)
|
||||||
|
|
||||||
assert isinstance(listdir.return_value, mocker.Mock)
|
assert isinstance(listdir.return_value, mocker.Mock)
|
||||||
assert open.side_effect is None
|
assert open.side_effect is None
|
||||||
|
|
||||||
|
if sys.version_info >= (3, 9):
|
||||||
|
# The reset on child mocks have been implemented in 3.9
|
||||||
|
# https://bugs.python.org/issue38932
|
||||||
|
assert mocked_object.run.return_value != "mocked"
|
||||||
|
|
||||||
|
|
||||||
class TestMockerStub:
|
class TestMockerStub:
|
||||||
def test_call(self, mocker: MockerFixture) -> None:
|
def test_call(self, mocker: MockerFixture) -> None:
|
||||||
|
|
6
tox.ini
6
tox.ini
|
@ -1,6 +1,6 @@
|
||||||
[tox]
|
[tox]
|
||||||
minversion = 3.5.3
|
minversion = 3.5.3
|
||||||
envlist = py{37,38,39,310,311}, norewrite
|
envlist = py{38,39,310,311,312}, norewrite
|
||||||
|
|
||||||
[testenv]
|
[testenv]
|
||||||
deps =
|
deps =
|
||||||
|
@ -8,11 +8,11 @@ deps =
|
||||||
mock
|
mock
|
||||||
pytest-asyncio
|
pytest-asyncio
|
||||||
commands =
|
commands =
|
||||||
coverage run --append --source={envsitepackagesdir}/pytest_mock -m pytest tests
|
coverage run --append --source={envsitepackagesdir}/pytest_mock -m pytest tests --color=yes
|
||||||
|
|
||||||
[testenv:norewrite]
|
[testenv:norewrite]
|
||||||
commands =
|
commands =
|
||||||
pytest tests --assert=plain
|
pytest tests --assert=plain --color=yes
|
||||||
|
|
||||||
[pytest]
|
[pytest]
|
||||||
addopts = -r a
|
addopts = -r a
|
||||||
|
|
Loading…
Reference in a new issue