Skip to content

Commit

Permalink
Configure asyncio_mode to fix tests
Browse files Browse the repository at this point in the history
Fix #272
  • Loading branch information
nicoddemus committed Jan 25, 2022
1 parent 3ca933a commit 0b869db
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
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
46 changes: 42 additions & 4 deletions tests/test_pytest_mock.py
Original file line number Diff line number Diff line change
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
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ commands = mypy {posargs:src tests}

[pytest]
addopts = -r a
asyncio_mode = auto

[flake8]
max-line-length = 88

0 comments on commit 0b869db

Please sign in to comment.