Skip to content

Commit

Permalink
refactor: Addressed warnigs about missing default fixture loop scope …
Browse files Browse the repository at this point in the history
…in tests/test_is_async_test.py, tests/test_simple.py, and tests/test_skips.py.
  • Loading branch information
seifertm committed Aug 25, 2024
1 parent 9fa18dd commit 60af27b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
4 changes: 4 additions & 0 deletions tests/test_is_async_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@


def test_returns_false_for_sync_item(pytester: Pytester):
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
pytester.makepyfile(
dedent(
"""\
Expand All @@ -28,6 +29,7 @@ def pytest_collection_modifyitems(items):


def test_returns_true_for_marked_coroutine_item_in_strict_mode(pytester: Pytester):
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
pytester.makepyfile(
dedent(
"""\
Expand All @@ -53,6 +55,7 @@ def pytest_collection_modifyitems(items):


def test_returns_false_for_unmarked_coroutine_item_in_strict_mode(pytester: Pytester):
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
pytester.makepyfile(
dedent(
"""\
Expand All @@ -77,6 +80,7 @@ def pytest_collection_modifyitems(items):


def test_returns_true_for_unmarked_coroutine_item_in_auto_mode(pytester: Pytester):
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
pytester.makepyfile(
dedent(
"""\
Expand Down
7 changes: 5 additions & 2 deletions tests/test_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ async def test_asyncio_marker():


def test_asyncio_marker_compatibility_with_xfail(pytester: Pytester):
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
pytester.makepyfile(
dedent(
"""\
Expand All @@ -45,6 +46,7 @@ async def test_asyncio_marker_fail():


def test_asyncio_auto_mode_compatibility_with_xfail(pytester: Pytester):
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
pytester.makepyfile(
dedent(
"""\
Expand Down Expand Up @@ -101,8 +103,9 @@ async def test_event_loop_before_fixture(self, loop):
assert await loop.run_in_executor(None, self.foo) == 1


def test_invalid_asyncio_mode(testdir):
result = testdir.runpytest("-o", "asyncio_mode=True")
def test_invalid_asyncio_mode(pytester):
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
result = pytester.runpytest("-o", "asyncio_mode=True")
result.stderr.no_fnmatch_line("INTERNALERROR> *")
result.stderr.fnmatch_lines(
"ERROR: 'True' is not a valid asyncio_mode. Valid modes: auto, strict."
Expand Down
7 changes: 7 additions & 0 deletions tests/test_skips.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@


def test_asyncio_strict_mode_skip(pytester: Pytester):
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
pytester.makepyfile(
dedent(
"""\
Expand All @@ -22,6 +23,7 @@ async def test_no_warning_on_skip():


def test_asyncio_auto_mode_skip(pytester: Pytester):
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
pytester.makepyfile(
dedent(
"""\
Expand All @@ -39,6 +41,7 @@ async def test_no_warning_on_skip():


def test_asyncio_strict_mode_module_level_skip(pytester: Pytester):
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
pytester.makepyfile(
dedent(
"""\
Expand All @@ -57,6 +60,7 @@ async def test_is_skipped():


def test_asyncio_auto_mode_module_level_skip(pytester: Pytester):
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
pytester.makepyfile(
dedent(
"""\
Expand All @@ -74,6 +78,7 @@ async def test_is_skipped():


def test_asyncio_auto_mode_wrong_skip_usage(pytester: Pytester):
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
pytester.makepyfile(
dedent(
"""\
Expand All @@ -91,6 +96,7 @@ async def test_is_skipped():


def test_unittest_skiptest_compatibility(pytester: Pytester):
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
pytester.makepyfile(
dedent(
"""\
Expand All @@ -108,6 +114,7 @@ async def test_is_skipped():


def test_skip_in_module_does_not_skip_package(pytester: Pytester):
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
pytester.makepyfile(
__init__="",
test_skip=dedent(
Expand Down

0 comments on commit 60af27b

Please sign in to comment.