Skip to content

Commit 13258c0

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

File tree

3 files changed

+48
-4
lines changed

3 files changed

+48
-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: 46 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):
@@ -769,11 +776,18 @@ def test(mocker):
769776
@pytest.mark.usefixtures("needs_assert_rewrite")
770777
def test_detailed_introspection_async(testdir: Any) -> None:
771778
"""Check that the "mock_use_standalone" is being used."""
779+
testdir.makeini(
780+
"""
781+
[pytest]
782+
asyncio_mode=strict
783+
"""
784+
)
772785
testdir.makepyfile(
773786
"""
774787
import pytest
788+
import pytest_asyncio
775789
776-
@pytest.mark.asyncio
790+
@pytest_asyncio.fixture
777791
async def test(mocker):
778792
m = mocker.AsyncMock()
779793
await m('fo')
@@ -824,6 +838,12 @@ def test_assert_called_with_unicode_arguments(mocker: MockerFixture) -> None:
824838

825839
def test_plain_stopall(testdir: Any) -> None:
826840
"""patch.stopall() in a test should not cause an error during unconfigure (#137)"""
841+
testdir.makeini(
842+
"""
843+
[pytest]
844+
asyncio_mode=strict
845+
"""
846+
)
827847
testdir.makepyfile(
828848
"""
829849
import random
@@ -958,6 +978,12 @@ def test_foo(mocker):
958978

959979

960980
def test_used_with_class_scope(testdir: Any) -> None:
981+
testdir.makeini(
982+
"""
983+
[pytest]
984+
asyncio_mode=strict
985+
"""
986+
)
961987
testdir.makepyfile(
962988
"""
963989
import pytest
@@ -982,6 +1008,12 @@ def test_get_random_number(self):
9821008

9831009

9841010
def test_used_with_module_scope(testdir: Any) -> None:
1011+
testdir.makeini(
1012+
"""
1013+
[pytest]
1014+
asyncio_mode=strict
1015+
"""
1016+
)
9851017
testdir.makepyfile(
9861018
"""
9871019
import pytest
@@ -1004,7 +1036,12 @@ def test_get_random_number():
10041036

10051037

10061038
def test_used_with_package_scope(testdir: Any) -> None:
1007-
"""..."""
1039+
testdir.makeini(
1040+
"""
1041+
[pytest]
1042+
asyncio_mode=strict
1043+
"""
1044+
)
10081045
testdir.makepyfile(
10091046
"""
10101047
import pytest
@@ -1027,7 +1064,12 @@ def test_get_random_number():
10271064

10281065

10291066
def test_used_with_session_scope(testdir: Any) -> None:
1030-
"""..."""
1067+
testdir.makeini(
1068+
"""
1069+
[pytest]
1070+
asyncio_mode=strict
1071+
"""
1072+
)
10311073
testdir.makepyfile(
10321074
"""
10331075
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)