Skip to content

Commit

Permalink
[test] Run some tests in a Pytester subprocess to avoid PytestAssertR…
Browse files Browse the repository at this point in the history
…ewriteWarning.

Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de>
  • Loading branch information
seifertm committed Jul 8, 2024
1 parent b77bff4 commit 81c5032
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions tests/hypothesis/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async def test_mark_inner(n):
"""
)
)
result = pytester.runpytest("--asyncio-mode=strict", "-W default")
result = pytester.runpytest_subprocess("--asyncio-mode=strict", "-W default")
result.assert_outcomes(passed=1)


Expand Down Expand Up @@ -67,7 +67,7 @@ async def test_explicit_fixture_request(event_loop, n):
"""
)
)
result = pytester.runpytest("--asyncio-mode=strict", "-W default")
result = pytester.runpytest_subprocess("--asyncio-mode=strict", "-W default")
result.assert_outcomes(passed=1, warnings=2)
result.stdout.fnmatch_lines(
[
Expand Down
2 changes: 1 addition & 1 deletion tests/markers/test_function_scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async def test_remember_loop(event_loop):
"""
)
)
result = pytester.runpytest("--asyncio-mode=strict", "-W default")
result = pytester.runpytest_subprocess("--asyncio-mode=strict", "-W default")
result.assert_outcomes(passed=1, warnings=1)
result.stdout.fnmatch_lines(
'*is asynchronous and explicitly requests the "event_loop" fixture*'
Expand Down
2 changes: 1 addition & 1 deletion tests/markers/test_module_scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def sample_fixture():
"""
)
)
result = pytester.runpytest("--asyncio-mode=strict", "-W default")
result = pytester.runpytest_subprocess("--asyncio-mode=strict", "-W default")
result.assert_outcomes(passed=2, warnings=2)
result.stdout.fnmatch_lines(
'*is asynchronous and explicitly requests the "event_loop" fixture*'
Expand Down
4 changes: 2 additions & 2 deletions tests/modes/test_strict_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ async def test_anything():
"""
)
)
result = testdir.runpytest("--asyncio-mode=strict", "-W default")
result = testdir.runpytest_subprocess("--asyncio-mode=strict", "-W default")
result.assert_outcomes(skipped=1, warnings=1)
result.stdout.fnmatch_lines(["*async def functions are not natively supported*"])

Expand All @@ -100,7 +100,7 @@ async def test_anything(any_fixture):
"""
)
)
result = testdir.runpytest("--asyncio-mode=strict", "-W default")
result = testdir.runpytest_subprocess("--asyncio-mode=strict", "-W default")
result.assert_outcomes(skipped=1, warnings=2)
result.stdout.fnmatch_lines(
[
Expand Down
14 changes: 7 additions & 7 deletions tests/test_asyncio_mark.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_a():
"""
)
)
result = pytester.runpytest("--asyncio-mode=strict", "-W default")
result = pytester.runpytest_subprocess("--asyncio-mode=strict", "-W default")
result.assert_outcomes(passed=1)
result.stdout.fnmatch_lines(
["*is marked with '@pytest.mark.asyncio' but it is not an async function.*"]
Expand All @@ -36,7 +36,7 @@ async def test_a():
"""
)
)
result = pytester.runpytest("--asyncio-mode=strict", "-W default")
result = pytester.runpytest_subprocess("--asyncio-mode=strict", "-W default")
result.assert_outcomes(xfailed=1, warnings=1)
result.stdout.fnmatch_lines(
["*Tests based on asynchronous generators are not supported*"]
Expand All @@ -54,7 +54,7 @@ async def test_a():
"""
)
)
result = pytester.runpytest("--asyncio-mode=auto", "-W default")
result = pytester.runpytest_subprocess("--asyncio-mode=auto", "-W default")
result.assert_outcomes(xfailed=1, warnings=1)
result.stdout.fnmatch_lines(
["*Tests based on asynchronous generators are not supported*"]
Expand All @@ -76,7 +76,7 @@ async def test_a(self):
"""
)
)
result = pytester.runpytest("--asyncio-mode=strict", "-W default")
result = pytester.runpytest_subprocess("--asyncio-mode=strict", "-W default")
result.assert_outcomes(xfailed=1, warnings=1)
result.stdout.fnmatch_lines(
["*Tests based on asynchronous generators are not supported*"]
Expand All @@ -96,7 +96,7 @@ async def test_a():
"""
)
)
result = pytester.runpytest("--asyncio-mode=auto", "-W default")
result = pytester.runpytest_subprocess("--asyncio-mode=auto", "-W default")
result.assert_outcomes(xfailed=1, warnings=1)
result.stdout.fnmatch_lines(
["*Tests based on asynchronous generators are not supported*"]
Expand All @@ -119,7 +119,7 @@ async def test_a():
"""
)
)
result = pytester.runpytest("--asyncio-mode=strict", "-W default")
result = pytester.runpytest_subprocess("--asyncio-mode=strict", "-W default")
result.assert_outcomes(xfailed=1, warnings=1)
result.stdout.fnmatch_lines(
["*Tests based on asynchronous generators are not supported*"]
Expand All @@ -139,7 +139,7 @@ async def test_a():
"""
)
)
result = pytester.runpytest("--asyncio-mode=auto", "-W default")
result = pytester.runpytest_subprocess("--asyncio-mode=auto", "-W default")
result.assert_outcomes(xfailed=1, warnings=1)
result.stdout.fnmatch_lines(
["*Tests based on asynchronous generators are not supported*"]
Expand Down
6 changes: 3 additions & 3 deletions tests/test_event_loop_fixture_finalizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ async def test_async_with_explicit_fixture_request(event_loop):
"""
)
)
result = pytester.runpytest("--asyncio-mode=strict", "-W default")
result = pytester.runpytest_subprocess("--asyncio-mode=strict", "-W default")
result.assert_outcomes(passed=1, warnings=1)
result.stdout.fnmatch_lines(
'*is asynchronous and explicitly requests the "event_loop" fixture*'
Expand Down Expand Up @@ -113,7 +113,7 @@ async def test_ends_with_unclosed_loop():
"""
)
)
result = pytester.runpytest("--asyncio-mode=strict", "-W", "default")
result = pytester.runpytest_subprocess("--asyncio-mode=strict", "-W", "default")
result.assert_outcomes(passed=1, warnings=2)
result.stdout.fnmatch_lines("*unclosed event loop*")

Expand All @@ -135,6 +135,6 @@ async def test_ends_with_unclosed_loop():
"""
)
)
result = pytester.runpytest("--asyncio-mode=strict", "-W", "default")
result = pytester.runpytest_subprocess("--asyncio-mode=strict", "-W", "default")
result.assert_outcomes(passed=1, warnings=1)
result.stdout.fnmatch_lines("*unclosed event loop*")
8 changes: 4 additions & 4 deletions tests/test_event_loop_fixture_override_deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async def test_emits_warning():
"""
)
)
result = pytester.runpytest("--asyncio-mode=strict", "-W default")
result = pytester.runpytest_subprocess("--asyncio-mode=strict", "-W default")
result.assert_outcomes(passed=1, warnings=1)
result.stdout.fnmatch_lines(
["*event_loop fixture provided by pytest-asyncio has been redefined*"]
Expand Down Expand Up @@ -50,7 +50,7 @@ async def test_emits_warning_when_requested_explicitly(event_loop):
"""
)
)
result = pytester.runpytest("--asyncio-mode=strict", "-W default")
result = pytester.runpytest_subprocess("--asyncio-mode=strict", "-W default")
result.assert_outcomes(passed=1, warnings=2)
result.stdout.fnmatch_lines(
["*event_loop fixture provided by pytest-asyncio has been redefined*"]
Expand Down Expand Up @@ -80,7 +80,7 @@ def test_emits_no_warning():
"""
)
)
result = pytester.runpytest("--asyncio-mode=strict")
result = pytester.runpytest_subprocess("--asyncio-mode=strict")
result.assert_outcomes(passed=1, warnings=0)


Expand All @@ -107,5 +107,5 @@ def test_emits_warning(uses_event_loop):
"""
)
)
result = pytester.runpytest("--asyncio-mode=strict", "-W default")
result = pytester.runpytest_subprocess("--asyncio-mode=strict", "-W default")
result.assert_outcomes(passed=1, warnings=1)
10 changes: 5 additions & 5 deletions tests/test_explicit_event_loop_fixture_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async def test_coroutine_emits_warning(event_loop):
"""
)
)
result = pytester.runpytest("--asyncio-mode=strict", "-W default")
result = pytester.runpytest_subprocess("--asyncio-mode=strict", "-W default")
result.assert_outcomes(passed=1, warnings=1)
result.stdout.fnmatch_lines(
['*is asynchronous and explicitly requests the "event_loop" fixture*']
Expand All @@ -39,7 +39,7 @@ async def test_coroutine_emits_warning(self, event_loop):
"""
)
)
result = pytester.runpytest("--asyncio-mode=strict", "-W default")
result = pytester.runpytest_subprocess("--asyncio-mode=strict", "-W default")
result.assert_outcomes(passed=1, warnings=1)
result.stdout.fnmatch_lines(
['*is asynchronous and explicitly requests the "event_loop" fixture*']
Expand All @@ -62,7 +62,7 @@ async def test_coroutine_emits_warning(event_loop):
"""
)
)
result = pytester.runpytest("--asyncio-mode=strict", "-W default")
result = pytester.runpytest_subprocess("--asyncio-mode=strict", "-W default")
result.assert_outcomes(passed=1, warnings=1)
result.stdout.fnmatch_lines(
['*is asynchronous and explicitly requests the "event_loop" fixture*']
Expand All @@ -88,7 +88,7 @@ async def test_uses_fixture(emits_warning):
"""
)
)
result = pytester.runpytest("--asyncio-mode=strict", "-W default")
result = pytester.runpytest_subprocess("--asyncio-mode=strict", "-W default")
result.assert_outcomes(passed=1, warnings=1)
result.stdout.fnmatch_lines(
['*is asynchronous and explicitly requests the "event_loop" fixture*']
Expand All @@ -114,7 +114,7 @@ async def test_uses_fixture(emits_warning):
"""
)
)
result = pytester.runpytest("--asyncio-mode=strict", "-W default")
result = pytester.runpytest_subprocess("--asyncio-mode=strict", "-W default")
result.assert_outcomes(passed=1, warnings=1)
result.stdout.fnmatch_lines(
['*is asynchronous and explicitly requests the "event_loop" fixture*']
Expand Down

0 comments on commit 81c5032

Please sign in to comment.