Skip to content

Commit 9acad36

Browse files
committed
Configure asyncio_mode to fix tests
Fix #272
1 parent 3ca933a commit 9acad36

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

mypy.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
disallow_any_generics = True
33
disallow_incomplete_defs = True
44
disallow_subclassing_any = True
5+
ignore_missing_imports = True
56
no_implicit_optional = True
67
pretty = True
78
show_error_codes = True

tests/test_pytest_mock.py

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from unittest.mock import MagicMock
1212

1313
import pytest
14+
import pytest_asyncio
1415

1516
from pytest_mock import MockerFixture
1617
from pytest_mock import PytestMockWarning
@@ -475,7 +476,7 @@ def __call__(self, x):
475476
assert spy.spy_return == 20
476477

477478

478-
@pytest.mark.asyncio
479+
@pytest_asyncio.fixture
479480
async def test_instance_async_method_spy(mocker: MockerFixture) -> None:
480481
class Foo:
481482
async def bar(self, arg):
@@ -728,6 +729,12 @@ def test_foo(mocker):
728729
@pytest.mark.usefixtures("needs_assert_rewrite")
729730
def test_detailed_introspection(testdir: Any) -> None:
730731
"""Check that the "mock_use_standalone" is being used."""
732+
testdir.makeini(
733+
"""
734+
[pytest]
735+
asyncio_mode=strict
736+
"""
737+
)
731738
testdir.makepyfile(
732739
"""
733740
def test(mocker):
@@ -772,8 +779,9 @@ def test_detailed_introspection_async(testdir: Any) -> None:
772779
testdir.makepyfile(
773780
"""
774781
import pytest
782+
import pytest_asyncio
775783
776-
@pytest.mark.asyncio
784+
@pytest_asyncio.fixture
777785
async def test(mocker):
778786
m = mocker.AsyncMock()
779787
await m('fo')
@@ -824,6 +832,12 @@ def test_assert_called_with_unicode_arguments(mocker: MockerFixture) -> None:
824832

825833
def test_plain_stopall(testdir: Any) -> None:
826834
"""patch.stopall() in a test should not cause an error during unconfigure (#137)"""
835+
testdir.makeini(
836+
"""
837+
[pytest]
838+
asyncio_mode=strict
839+
"""
840+
)
827841
testdir.makepyfile(
828842
"""
829843
import random
@@ -958,6 +972,12 @@ def test_foo(mocker):
958972

959973

960974
def test_used_with_class_scope(testdir: Any) -> None:
975+
testdir.makeini(
976+
"""
977+
[pytest]
978+
asyncio_mode=strict
979+
"""
980+
)
961981
testdir.makepyfile(
962982
"""
963983
import pytest
@@ -982,6 +1002,12 @@ def test_get_random_number(self):
9821002

9831003

9841004
def test_used_with_module_scope(testdir: Any) -> None:
1005+
testdir.makeini(
1006+
"""
1007+
[pytest]
1008+
asyncio_mode=strict
1009+
"""
1010+
)
9851011
testdir.makepyfile(
9861012
"""
9871013
import pytest
@@ -1004,7 +1030,12 @@ def test_get_random_number():
10041030

10051031

10061032
def test_used_with_package_scope(testdir: Any) -> None:
1007-
"""..."""
1033+
testdir.makeini(
1034+
"""
1035+
[pytest]
1036+
asyncio_mode=strict
1037+
"""
1038+
)
10081039
testdir.makepyfile(
10091040
"""
10101041
import pytest
@@ -1027,7 +1058,12 @@ def test_get_random_number():
10271058

10281059

10291060
def test_used_with_session_scope(testdir: Any) -> None:
1030-
"""..."""
1061+
testdir.makeini(
1062+
"""
1063+
[pytest]
1064+
asyncio_mode=strict
1065+
"""
1066+
)
10311067
testdir.makepyfile(
10321068
"""
10331069
import pytest

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ commands = mypy {posargs:src tests}
2828

2929
[pytest]
3030
addopts = -r a
31+
asyncio_mode = strict
3132

3233
[flake8]
3334
max-line-length = 88

0 commit comments

Comments
 (0)