Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ jobs:
strategy:
fail-fast: false
matrix:
python: ["3.6", "3.7", "3.8", "3.9"]
python: ["3.7", "3.8", "3.9", "3.10"]
os: [ubuntu-latest, windows-latest]
include:
- python: "3.6"
tox_env: "py36"
- python: "3.7"
tox_env: "py37"
- python: "3.8"
tox_env: "py38"
- python: "3.9"
tox_env: "py39"
- python: "3.10"
tox_env: "py310"

steps:
- uses: actions/checkout@v1
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
3.7.0 (UNRELEASED)
------------------

* Python 3.10 now officially supported.
* Dropped support for Python 3.6.

3.6.1 (2021-05-06)
------------------

Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
disallow_any_generics = True
disallow_incomplete_defs = True
disallow_subclassing_any = True
ignore_missing_imports = True
no_implicit_optional = True
pretty = True
show_error_codes = True
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
package_data={
"pytest_mock": ["py.typed"],
},
python_requires=">=3.6",
python_requires=">=3.7",
install_requires=["pytest>=5.0"],
use_scm_version={"write_to": "src/pytest_mock/_version.py"},
setup_requires=["setuptools_scm"],
Expand All @@ -31,10 +31,10 @@
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3 :: Only",
"Topic :: Software Development :: Testing",
],
Expand Down
56 changes: 47 additions & 9 deletions tests/test_pytest_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def test_repr_with_no_name(self, mocker: MockerFixture) -> None:
def test_repr_with_name(self, mocker: MockerFixture) -> None:
test_name = "funny walk"
stub = mocker.stub(name=test_name)
assert "name={!r}".format(test_name) in repr(stub)
assert f"name={test_name!r}" in repr(stub)

def __test_failure_message(self, mocker: MockerFixture, **kwargs: Any) -> None:
expected_name = kwargs.get("name") or "mock"
Expand Down Expand Up @@ -267,19 +267,19 @@ def test_instance_method_spy_exception(
) -> None:
class Foo:
def bar(self, arg):
raise exc_cls("Error with {}".format(arg))
raise exc_cls(f"Error with {arg}")

foo = Foo()
spy = mocker.spy(foo, "bar")

expected_calls = []
for i, v in enumerate([10, 20]):
with pytest.raises(exc_cls, match="Error with {}".format(v)):
with pytest.raises(exc_cls, match=f"Error with {v}"):
foo.bar(arg=v)

expected_calls.append(mocker.call(arg=v))
assert foo.bar.call_args_list == expected_calls # type:ignore[attr-defined]
assert str(spy.spy_exception) == "Error with {}".format(v)
assert str(spy.spy_exception) == f"Error with {v}"


def test_instance_method_spy_autospec_true(mocker: MockerFixture) -> None:
Expand All @@ -296,7 +296,7 @@ def bar(self, arg):


def test_spy_reset(mocker: MockerFixture) -> None:
class Foo(object):
class Foo:
def bar(self, x):
if x == 0:
raise ValueError("invalid x")
Expand Down Expand Up @@ -475,7 +475,6 @@ def __call__(self, x):
assert spy.spy_return == 20


@pytest.mark.asyncio
async def test_instance_async_method_spy(mocker: MockerFixture) -> None:
class Foo:
async def bar(self, arg):
Expand Down Expand Up @@ -728,6 +727,12 @@ def test_foo(mocker):
@pytest.mark.usefixtures("needs_assert_rewrite")
def test_detailed_introspection(testdir: Any) -> None:
"""Check that the "mock_use_standalone" is being used."""
testdir.makeini(
"""
[pytest]
asyncio_mode=auto
"""
)
testdir.makepyfile(
"""
def test(mocker):
Expand Down Expand Up @@ -769,11 +774,16 @@ def test(mocker):
@pytest.mark.usefixtures("needs_assert_rewrite")
def test_detailed_introspection_async(testdir: Any) -> None:
"""Check that the "mock_use_standalone" is being used."""
testdir.makeini(
"""
[pytest]
asyncio_mode=auto
"""
)
testdir.makepyfile(
"""
import pytest

@pytest.mark.asyncio
async def test(mocker):
m = mocker.AsyncMock()
await m('fo')
Expand Down Expand Up @@ -824,6 +834,12 @@ def test_assert_called_with_unicode_arguments(mocker: MockerFixture) -> None:

def test_plain_stopall(testdir: Any) -> None:
"""patch.stopall() in a test should not cause an error during unconfigure (#137)"""
testdir.makeini(
"""
[pytest]
asyncio_mode=auto
"""
)
testdir.makepyfile(
"""
import random
Expand Down Expand Up @@ -958,6 +974,12 @@ def test_foo(mocker):


def test_used_with_class_scope(testdir: Any) -> None:
testdir.makeini(
"""
[pytest]
asyncio_mode=auto
"""
)
testdir.makepyfile(
"""
import pytest
Expand All @@ -982,6 +1004,12 @@ def test_get_random_number(self):


def test_used_with_module_scope(testdir: Any) -> None:
testdir.makeini(
"""
[pytest]
asyncio_mode=auto
"""
)
testdir.makepyfile(
"""
import pytest
Expand All @@ -1004,7 +1032,12 @@ def test_get_random_number():


def test_used_with_package_scope(testdir: Any) -> None:
"""..."""
testdir.makeini(
"""
[pytest]
asyncio_mode=auto
"""
)
testdir.makepyfile(
"""
import pytest
Expand All @@ -1027,7 +1060,12 @@ def test_get_random_number():


def test_used_with_session_scope(testdir: Any) -> None:
"""..."""
testdir.makeini(
"""
[pytest]
asyncio_mode=auto
"""
)
testdir.makepyfile(
"""
import pytest
Expand Down
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
minversion = 3.5.3
envlist = py{35,36,37,38,39}, linting, norewrite
envlist = py{37,38,39,310}, linting, norewrite

[testenv]
passenv = USER USERNAME
Expand Down Expand Up @@ -28,6 +28,7 @@ commands = mypy {posargs:src tests}

[pytest]
addopts = -r a
asyncio_mode = auto

[flake8]
max-line-length = 88